Skip to content

Commit

Permalink
test(integration): add a common test between repo and client/server
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed May 24, 2024
1 parent 36e007e commit 2176359
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
13 changes: 8 additions & 5 deletions integration/client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ type csArgs struct {

func TestClientServer(t *testing.T) {
tests := []struct {
name string
args csArgs
golden string
wantErr string
name string
args csArgs
golden string
override func(t *testing.T, want, got *types.Report)
}{
{
name: "alpine 3.9",
Expand Down Expand Up @@ -270,6 +270,9 @@ func TestClientServer(t *testing.T) {
Target: "https://github.com/knqyf263/trivy-ci-test",
},
golden: "testdata/test-repo.json.golden",
override: func(t *testing.T, want, got *types.Report) {
want.ArtifactName = "https://github.com/knqyf263/trivy-ci-test"
},
},
}

Expand All @@ -284,7 +287,7 @@ func TestClientServer(t *testing.T) {
}

runTest(t, osArgs, tt.golden, "", types.FormatJSON, runOptions{
override: overrideUID,
override: overrideFuncs(overrideUID, tt.override),
})
})
}
Expand Down
8 changes: 8 additions & 0 deletions integration/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ func TestRepository(t *testing.T) {
},
golden: "testdata/composer.lock.json.golden",
},
{
name: "multiple lockfiles",
args: args{
scanner: types.VulnerabilityScanner,
input: "testdata/fixtures/repo/trivy-ci-test",
},
golden: "testdata/test-repo.json.golden",
},
{
name: "dockerfile",
args: args{
Expand Down
1 change: 1 addition & 0 deletions integration/testdata/fixtures/repo/trivy-ci-test
Submodule trivy-ci-test added at 17728b
7 changes: 6 additions & 1 deletion integration/testdata/test-repo.json.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"SchemaVersion": 2,
"CreatedAt": "2021-08-25T12:20:30.000000005Z",
"ArtifactName": "https://github.com/knqyf263/trivy-ci-test",
"ArtifactName": "testdata/fixtures/repo/trivy-ci-test",
"ArtifactType": "repository",
"Metadata": {
"ImageConfig": {
Expand Down Expand Up @@ -109,6 +109,11 @@
"LastModifiedDate": "2021-08-16T16:37:00Z"
}
]
},
{
"Target": "Pipfile.lock",
"Class": "lang-pkgs",
"Type": "pipenv"
}
]
}

0 comments on commit 2176359

Please sign in to comment.