Skip to content

Commit

Permalink
Merge pull request #3308 from mercedes-benz/feature-3307-client-no-up…
Browse files Browse the repository at this point in the history
…loadfiles-when-remote

cleanup empty files when remote-data-section #3307
  • Loading branch information
sven-dmlr authored Jul 16, 2024
2 parents 4833b87 + 634bd5b commit f8b4c2a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
12 changes: 6 additions & 6 deletions sechub-cli/src/mercedes-benz.com/sechub/cli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ func prepareScan(context *Context) {
sechubUtil.LogError(fmt.Sprintf("%s\nExiting due to fatal error while creating sources zip file...\n", err))
os.Remove(context.sourceZipFileName) // cleanup zip file
os.Exit(ExitCodeFailed)
} else if context.sourceZipUploadNeeded {
// calculate checksum for zip file
context.sourceZipFileChecksum = sechubUtil.CreateChecksum(context.sourceZipFileName)
}

// calculate checksum for zip file
context.sourceZipFileChecksum = sechubUtil.CreateChecksum(context.sourceZipFileName)
} else {
context.sourceZipUploadNeeded = false
}
Expand All @@ -156,10 +156,10 @@ func prepareScan(context *Context) {
sechubUtil.LogError(fmt.Sprintf("%s\nExiting due to fatal error while creating binaries tar file...\n", err))
os.Remove(context.binariesTarFileName) // cleanup tar file
os.Exit(ExitCodeFailed)
} else if context.binariesTarUploadNeeded {
// calculate checksum for tar file
context.binariesTarFileChecksum = sechubUtil.CreateChecksum(context.binariesTarFileName)
}

// calculate checksum for tar file
context.binariesTarFileChecksum = sechubUtil.CreateChecksum(context.binariesTarFileName)
} else {
context.binariesTarUploadNeeded = false
}
Expand Down
1 change: 1 addition & 0 deletions sechub-cli/src/mercedes-benz.com/sechub/cli/tarbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func createBinariesTarFile(context *Context) error {
}
}
} else {
os.Remove(context.binariesTarFileName)
context.binariesTarUploadNeeded = false
sechubUtil.LogNotice(sechubUtil.TarFileNotCreated)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,5 @@ func Test_createBinariesTarFile_HandlesRemoteDataSection(t *testing.T) {
/* test */
sechubTestUtil.AssertNoError(err, t)
sechubTestUtil.AssertStringContains(string(out), sechubUtil.TarFileNotCreated, t)
sechubTestUtil.AssertFileNotExists(context.binariesTarFileName, t)
}
1 change: 1 addition & 0 deletions sechub-cli/src/mercedes-benz.com/sechub/cli/zipbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func createSouceCodeZipFile(context *Context) error {
}
}
} else {
os.Remove(context.sourceZipFileName)
context.sourceZipUploadNeeded = false
sechubUtil.LogNotice(sechubUtil.ZipFileNotCreated)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@ func Test_createSouceCodeZipFile_HandleRemoteDataSection(t *testing.T) {
/* test */
sechubTestUtil.AssertNoError(err, t)
sechubTestUtil.AssertStringContains(string(out), sechubUtil.ZipFileNotCreated, t)
sechubTestUtil.AssertFileNotExists(context.sourceZipFileName, t)
}
11 changes: 10 additions & 1 deletion sechub-cli/src/mercedes-benz.com/sechub/testutil/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package util

import (
"encoding/json"
"errors"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -142,13 +143,21 @@ func jsonBytesEqual(a, b []byte) (bool, error) {
// AssertFileExists - checks if a file exists
func AssertFileExists(filePath string, t *testing.T) {
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
t.Fatalf("File %q expected, but does not exist.", filePath)
} else {
Check(err, t)
}
}

// AssertFileNotExists - checks if a file does not exist
func AssertFileNotExists(filePath string, t *testing.T) {
_, err := os.Stat(filePath)
if ! errors.Is(err, os.ErrNotExist) {
t.Fatalf("File %q exists but it should not.", filePath)
}
}

// AssertMinimalFileSize - checks a file's size to be at least `size` bytes
func AssertMinimalFileSize(filePath string, size int64, t *testing.T) {
fileinfo, err := os.Stat(filePath)
Expand Down

0 comments on commit f8b4c2a

Please sign in to comment.