Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g
DebrickedConfig: dScanner.getDebrickedConfig(options.Path, options.Exclusions, options.Inclusions),
TagCommitAsRelease: options.TagCommitAsRelease,
Experimental: options.Experimental,
NoResolve: !options.Resolve,
}
result, err := (*dScanner.uploader).Upload(uploaderOptions)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/upload/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ type uploadBatch struct {
debrickedConfig *DebrickedConfig // JSON Config
tagCommitAsRelease bool
experimental bool
noResolve bool
}

func newUploadBatch(
client *client.IDebClient, fileGroups file.Groups, gitMetaObject *git.MetaObject,
integrationName string, callGraphTimeout int, versionHint bool,
debrickedConfig *DebrickedConfig, tagCommitAsRelease bool, experimental bool,
debrickedConfig *DebrickedConfig, tagCommitAsRelease bool, experimental bool, noResolve bool,
) *uploadBatch {
return &uploadBatch{
client: client,
Expand All @@ -65,6 +66,7 @@ func newUploadBatch(
debrickedConfig: debrickedConfig,
tagCommitAsRelease: tagCommitAsRelease,
experimental: experimental,
noResolve: noResolve,
}
}

Expand Down Expand Up @@ -194,6 +196,7 @@ func (uploadBatch *uploadBatch) initAnalysis() error {
DebrickedIntegration: "cli",
TagCommitAsRelease: uploadBatch.tagCommitAsRelease,
Experimental: uploadBatch.experimental,
NoResolve: uploadBatch.noResolve,
})

if err != nil {
Expand Down Expand Up @@ -363,6 +366,7 @@ type uploadFinish struct {
DebrickedConfig *DebrickedConfig `json:"debrickedConfig"`
TagCommitAsRelease bool `json:"isRelease"`
Experimental bool `json:"experimental"`
NoResolve bool `json:"noResolve"`
}

func getRelativeFilePath(filePath string) string {
Expand Down
54 changes: 47 additions & 7 deletions internal/upload/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestUploadWithBadFiles(t *testing.T) {
clientMock.AddMockResponse(mockRes)
clientMock.AddMockResponse(mockRes)
c = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false, false)
var buf bytes.Buffer
log.SetOutput(&buf)
err = batch.upload()
Expand All @@ -50,12 +50,52 @@ func TestUploadWithBadFiles(t *testing.T) {
}

func TestInitAnalysisWithoutAnyFiles(t *testing.T) {
batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, true, false, false)
err := batch.initAnalysis()

assert.ErrorContains(t, err, "failed to find dependency files")
}

func TestInitAnalysisNoResolve(t *testing.T) {
metaObj, err := git.NewMetaObject("", "repository-name", "commit-name", "", "", "")
if err != nil {
t.Fatal("failed to create new MetaObject")
}

clientMock := testdata.NewDebClientMock()
clientMock.AddMockResponse(testdata.MockResponse{
StatusCode: http.StatusNoContent,
ResponseBody: io.NopCloser(strings.NewReader("")),
})
var c client.IDebClient = clientMock
batch := newUploadBatch(&c, file.Groups{}, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false, false, true)
batch.ciUploadId = 1

assert.True(t, batch.noResolve)
err = batch.initAnalysis()
assert.NoError(t, err)
}

func TestUploadFinishNoResolveJSON(t *testing.T) {
finish := uploadFinish{
CiUploadId: "1",
NoResolve: true,
}
body, err := json.Marshal(finish)
assert.NoError(t, err)
assert.Contains(t, string(body), `"noResolve":true`)
}

func TestUploadFinishResolveJSON(t *testing.T) {
finish := uploadFinish{
CiUploadId: "1",
NoResolve: false,
}
body, err := json.Marshal(finish)
assert.NoError(t, err)
assert.Contains(t, string(body), `"noResolve":false`)
}

func TestWaitWithPollingTerminatedError(t *testing.T) {
group := file.NewGroup("package.json", nil, []string{"yarn.lock"})
var groups file.Groups
Expand All @@ -73,7 +113,7 @@ func TestWaitWithPollingTerminatedError(t *testing.T) {
}
clientMock.AddMockResponse(mockRes)
c = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false, false)

uploadResult, err := batch.wait()

Expand All @@ -98,7 +138,7 @@ func TestInitUploadBadFile(t *testing.T) {
clientMock.AddMockResponse(mockRes)

var c client.IDebClient = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false, false)

files, err := batch.initUpload()

Expand All @@ -120,7 +160,7 @@ func TestInitUploadFingerprintsFree(t *testing.T) {
clientMock := testdata.NewDebClientMock()
clientMock.SetEnterpriseCustomer(false)
var c client.IDebClient = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false, false)

files, err := batch.initUpload()

Expand All @@ -145,7 +185,7 @@ func TestInitUpload(t *testing.T) {
clientMock.AddMockResponse(mockRes)

var c client.IDebClient = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false, false)

files, err := batch.initUpload()

Expand Down Expand Up @@ -388,7 +428,7 @@ func TestInitUploadSPDX(t *testing.T) {
clientMock.AddMockResponse(mockRes)

var c client.IDebClient = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false, false)

files, err := batch.initUpload()

Expand Down
2 changes: 2 additions & 0 deletions internal/upload/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type DebrickedOptions struct {
DebrickedConfig *DebrickedConfig
TagCommitAsRelease bool
Experimental bool
NoResolve bool
}

type IUploader interface {
Expand Down Expand Up @@ -49,6 +50,7 @@ func (uploader *Uploader) Upload(o IOptions) (*UploadResult, error) {
dOptions.DebrickedConfig,
dOptions.TagCommitAsRelease,
dOptions.Experimental,
dOptions.NoResolve,
)

err := batch.upload()
Expand Down
Loading