Skip to content

Commit 0b8bc6f

Browse files
fixed error msgs
1 parent 0f45a2e commit 0b8bc6f

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

internal/commands/scan_test.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ func TestScanCreate_ApplicationNameIsNotExactMatch_FailedToCreateScan(t *testing
193193
assert.Assert(t, err.Error() == errorConstants.ApplicationDoesntExistOrNoPermission)
194194
}
195195

196-
func TestScanCreate_ExistingProjectAndApplicationWithNoPermission_ShouldCreateScan(t *testing.T) {
197-
execCmdNilAssertion(t, "scan", "create", "--project-name", "MOCK", "--application-name", mock.ApplicationDoesntExist, "-s", dummyRepo, "-b", "dummy_branch")
196+
func TestScanCreate_ExistingProjectAndApplicationWithNoPermission_ShouldFailScan(t *testing.T) {
197+
err := execCmdNotNilAssertion(t, "scan", "create", "--project-name", "MOCK", "--application-name", mock.NoPermissionApp, "-s", dummyRepo, "-b", "dummy_branch")
198+
assert.Assert(t, strings.Contains(err.Error(), errorConstants.FailedToGetApplication), err.Error())
198199
}
199200

200201
func TestScanCreate_ExistingApplicationWithNoPermission_FailedToCreateScan(t *testing.T) {
@@ -712,18 +713,13 @@ func TestCreateScan_WhenProjectExists_ShouldIgnoreGroups(t *testing.T) {
712713
assert.Equal(t, strings.Contains(stdoutString, noUpdatesForExistingProject), true, "Expected output: %s", noUpdatesForExistingProject)
713714
}
714715

715-
func TestCreateScan_WhenProjectExists_ShouldIgnoreApplication(t *testing.T) {
716-
file := createOutputFile(t, outputFileName)
717-
defer deleteOutputFile(file)
718-
defer logger.SetOutput(os.Stdout)
716+
// Now as we give the ability to assign existing projects to applications , there is validation if application exists
717+
718+
func TestCreateScan_WhenProjectExists_GetApplication_Fails500Err_Failed(t *testing.T) {
719719
baseArgs := []string{scanCommand, "create", "--project-name", "MOCK", "-s", dummyRepo, "-b", "dummy_branch",
720-
"--debug", "--application-name", "anyApplication"}
721-
execCmdNilAssertion(t, baseArgs...)
722-
stdoutString, err := util.ReadFileAsString(file.Name())
723-
if err != nil {
724-
t.Fatalf("Failed to read log file: %v", err)
725-
}
726-
assert.Equal(t, strings.Contains(stdoutString, noUpdatesForExistingProject), true, "Expected output: %s", noUpdatesForExistingProject)
720+
"--debug", "--application-name", mock.FakeInternalServerError500}
721+
err := execCmdNotNilAssertion(t, baseArgs...)
722+
assert.ErrorContains(t, err, errorConstants.FailedToGetApplication, err.Error())
727723
}
728724
func TestScanCreateLastSastScanTimeWithInvalidValue(t *testing.T) {
729725
baseArgs := []string{"scan", "create", "--project-name", "MOCK", "-s", dummyRepo, "-b", "dummy_branch", "--sca-exploitable-path", "true", "--sca-last-sast-scan-time", "notaniteger"}
@@ -3664,5 +3660,6 @@ func Test_CreateScanWithExistingProjectAndAssign_FailedApplication_DoesNot_Exist
36643660
t,
36653661
baseArgs...,
36663662
)
3667-
assert.Error(t, err, "Failed to get Application NoPermissionApp: provided application does not exist or user has no permission to the application", err.Error())
3663+
assert.ErrorContains(t, err, errorConstants.FailedToGetApplication, err.Error())
3664+
36683665
}

internal/services/applications.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func findApplicationAndUpdate(applicationName string, applicationsWrapper wrappe
7171
}
7272
applicationResp, err := GetApplication(applicationName, applicationsWrapper)
7373
if err != nil {
74-
return errors.Wrapf(err, "Failed to get Application:%s", applicationName)
74+
return errors.Wrapf(err, "%s:%s", errorConstants.FailedToGetApplication, applicationName)
7575
}
7676
if applicationResp == nil {
77-
return errors.Errorf("Application %s not found", applicationName)
77+
return errors.Errorf("Application not found: %s", applicationName)
7878
}
7979
var applicationModel wrappers.ApplicationConfiguration
8080
var newApplicationRule wrappers.Rule

0 commit comments

Comments
 (0)