Skip to content

Commit

Permalink
test: CGS connect negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhi-nair committed Dec 11, 2024
1 parent dcdd52f commit 3a3c9f4
Show file tree
Hide file tree
Showing 4 changed files with 505 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,27 +371,7 @@ public Mono<? extends Artifact> connectArtifactToGit(
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ORIGIN));
}

Mono<UserData> currentUserMono = userDataService
.getForCurrentUser()
.filter(userData -> !CollectionUtils.isEmpty(userData.getGitProfiles()))
.switchIfEmpty(
Mono.error(new AppsmithException(AppsmithError.INVALID_GIT_CONFIGURATION, GIT_PROFILE_ERROR)));

Mono<GitUser> gitUserMono = currentUserMono
.map(userData -> {
GitProfile profile = userData.getGitProfileByKey(baseArtifactId);
if (profile == null
|| Boolean.TRUE.equals(profile.getUseGlobalProfile())
|| !StringUtils.hasText(profile.getAuthorName())) {
profile = userData.getGitProfileByKey(DEFAULT);
}

GitUser gitUser = new GitUser();
gitUser.setName(profile.getAuthorName());
gitUser.setEmail(profile.getAuthorEmail());
return gitUser;
})
.cache();
Mono<GitUser> gitUserMono = getGitUserForArtifactId(baseArtifactId);

Mono<Map<String, GitProfile>> profileMono = gitProfileUtils
.updateOrCreateGitProfileForCurrentUser(gitConnectDTO.getGitProfile(), baseArtifactId)
Expand Down Expand Up @@ -441,9 +421,10 @@ public Mono<? extends Artifact> connectArtifactToGit(
.onErrorResume(error -> {
log.error("Error while cloning the remote repo, ", error);

AppsmithException appsmithException =
new AppsmithException(AppsmithError.GIT_GENERIC_ERROR, error.getMessage());
if (error instanceof TransportException) {
AppsmithException appsmithException = null;
if (error instanceof AppsmithException e) {
appsmithException = e;
} else if (error instanceof TransportException) {
appsmithException =
new AppsmithException(AppsmithError.INVALID_GIT_SSH_CONFIGURATION);
} else if (error instanceof InvalidRemoteException) {
Expand All @@ -458,6 +439,9 @@ public Mono<? extends Artifact> connectArtifactToGit(
appsmithException =
new AppsmithException(AppsmithError.INVALID_GIT_SSH_URL);
}
} else {
appsmithException = new AppsmithException(
AppsmithError.GIT_GENERIC_ERROR, error.getMessage());
}

ArtifactJsonTransformationDTO jsonTransformationDTO =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ public Mono<String> fetchRemoteRepository(
} else if (error instanceof TimeoutException) {
return Mono.error(new AppsmithException(AppsmithError.GIT_EXECUTION_TIMEOUT));
}
return Mono.error(
new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "clone", error));
return Mono.error(new AppsmithException(
AppsmithError.GIT_ACTION_FAILED, "clone", error.getMessage()));
});
});
}
Expand Down Expand Up @@ -325,13 +325,16 @@ public Mono<String> createFirstCommit(ArtifactJsonTransformationDTO jsonTransfor
jsonTransformationDTO.getBaseArtifactId(),
jsonTransformationDTO.getRepoName());

return fsGitHandler.commitArtifact(
repoSuffix,
commitDTO.getMessage(),
commitDTO.getAuthor().getName(),
commitDTO.getAuthor().getEmail(),
true,
commitDTO.getIsAmendCommit());
return fsGitHandler
.commitArtifact(
repoSuffix,
commitDTO.getMessage(),
commitDTO.getAuthor().getName(),
commitDTO.getAuthor().getEmail(),
true,
commitDTO.getIsAmendCommit())
.onErrorResume(error -> Mono.error(
new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "commit", error.getMessage())));
}

@Override
Expand Down
Loading

0 comments on commit 3a3c9f4

Please sign in to comment.