Skip to content

Commit

Permalink
test(integration): fix
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Apr 20, 2023
1 parent af9c9d0 commit f1eed9b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
6 changes: 3 additions & 3 deletions pkg/fanal/test/integration/containerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestContainerd_SearchLocalStoreByNameOrDigest(t *testing.T) {
}
})

img, cleanup, err := image.NewContainerImage(ctx, tt.searchName, types.RemoteOptions{},
img, cleanup, err := image.NewContainerImage(ctx, tt.searchName, types.RegistryOptions{},
image.DisableDockerd(), image.DisablePodman(), image.DisableRemote())
defer cleanup()
if tt.expectErr {
Expand Down Expand Up @@ -679,7 +679,7 @@ func localImageTestWithNamespace(t *testing.T, namespace string) {
require.NoError(t, err)

// Enable only containerd
img, cleanup, err := image.NewContainerImage(ctx, tt.imageName, types.RemoteOptions{},
img, cleanup, err := image.NewContainerImage(ctx, tt.imageName, types.RegistryOptions{},
image.DisableDockerd(), image.DisablePodman(), image.DisableRemote())
require.NoError(t, err)
defer cleanup()
Expand Down Expand Up @@ -814,7 +814,7 @@ func TestContainerd_PullImage(t *testing.T) {
require.NoError(t, err)

// Enable only containerd
img, cleanup, err := image.NewContainerImage(ctx, tt.imageName, types.RemoteOptions{},
img, cleanup, err := image.NewContainerImage(ctx, tt.imageName, types.RegistryOptions{},
image.DisableDockerd(), image.DisablePodman(), image.DisableRemote())
require.NoError(t, err)
defer cleanup()
Expand Down
4 changes: 2 additions & 2 deletions pkg/fanal/test/integration/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestFanal_Library_DockerLessMode(t *testing.T) {
})

// Enable only registry scanning
img, cleanup, err := image.NewContainerImage(ctx, tt.remoteImageName, types.RemoteOptions{},
img, cleanup, err := image.NewContainerImage(ctx, tt.remoteImageName, types.ImageOptions{},
image.DisableDockerd(), image.DisablePodman(), image.DisableContainerd())
require.NoError(t, err)
defer cleanup()
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestFanal_Library_DockerMode(t *testing.T) {
require.NoError(t, err, tt.name)

// Enable only dockerd scanning
img, cleanup, err := image.NewContainerImage(ctx, tt.remoteImageName, types.RemoteOptions{},
img, cleanup, err := image.NewContainerImage(ctx, tt.remoteImageName, types.ImageOptions{},
image.DisablePodman(), image.DisableContainerd(), image.DisableRemote())
require.NoError(t, err, tt.name)
defer cleanup()
Expand Down
45 changes: 26 additions & 19 deletions pkg/fanal/test/integration/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (
"path/filepath"
"testing"

"github.com/aquasecurity/trivy/pkg/fanal/analyzer"

"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
testcontainers "github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
"github.com/aquasecurity/trivy/pkg/fanal/applier"
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
Expand Down Expand Up @@ -83,7 +82,7 @@ func TestTLSRegistry(t *testing.T) {
name string
imageName string
imageFile string
option types.RemoteOptions
option types.ImageOptions
login bool
expectedOS types.OS
expectedRepo types.Repository
Expand All @@ -93,14 +92,16 @@ func TestTLSRegistry(t *testing.T) {
name: "happy path",
imageName: "ghcr.io/aquasecurity/trivy-test-images:alpine-310",
imageFile: "../../../../integration/testdata/fixtures/images/alpine-310.tar.gz",
option: types.RemoteOptions{
Credentials: []types.Credential{
{
Username: registryUsername,
Password: registryPassword,
option: types.ImageOptions{
RegistryOptions: types.RegistryOptions{
Credentials: []types.Credential{
{
Username: registryUsername,
Password: registryPassword,
},
},
Insecure: true,
},
Insecure: true,
},
expectedOS: types.OS{
Name: "3.10.2",
Expand All @@ -116,8 +117,10 @@ func TestTLSRegistry(t *testing.T) {
name: "happy path with docker login",
imageName: "ghcr.io/aquasecurity/trivy-test-images:alpine-310",
imageFile: "../../../../integration/testdata/fixtures/images/alpine-310.tar.gz",
option: types.RemoteOptions{
Insecure: true,
option: types.ImageOptions{
RegistryOptions: types.RegistryOptions{
Insecure: true,
},
},
login: true,
expectedOS: types.OS{
Expand All @@ -134,11 +137,13 @@ func TestTLSRegistry(t *testing.T) {
name: "sad path: tls verify",
imageName: "ghcr.io/aquasecurity/trivy-test-images:alpine-310",
imageFile: "../../../../integration/testdata/fixtures/images/alpine-310.tar.gz",
option: types.RemoteOptions{
Credentials: []types.Credential{
{
Username: registryUsername,
Password: registryPassword,
option: types.ImageOptions{
RegistryOptions: types.RegistryOptions{
Credentials: []types.Credential{
{
Username: registryUsername,
Password: registryPassword,
},
},
},
},
Expand All @@ -148,8 +153,10 @@ func TestTLSRegistry(t *testing.T) {
name: "sad path: no credential",
imageName: "ghcr.io/aquasecurity/trivy-test-images:alpine-310",
imageFile: "../../../../integration/testdata/fixtures/images/alpine-310.tar.gz",
option: types.RemoteOptions{
Insecure: true,
option: types.ImageOptions{
RegistryOptions: types.RegistryOptions{
Insecure: true,
},
},
wantErr: true,
},
Expand Down Expand Up @@ -200,7 +207,7 @@ func getRegistryURL(ctx context.Context, registryC testcontainers.Container, exp
return url.Parse(urlStr)
}

func analyze(ctx context.Context, imageRef string, opt types.RemoteOptions) (*types.ArtifactDetail, error) {
func analyze(ctx context.Context, imageRef string, opt types.ImageOptions) (*types.ArtifactDetail, error) {
d, err := ioutil.TempDir("", "TestRegistry-*")
if err != nil {
return nil, err
Expand Down

0 comments on commit f1eed9b

Please sign in to comment.