Skip to content

Commit

Permalink
test: Refactor linting tests and add Trivy integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaredevelop committed Mar 21, 2024
1 parent 6b45abc commit 0920bbc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
18 changes: 17 additions & 1 deletion cc/linting/t_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,23 @@ func TestT(t *testing.T) {

t.Run("Test_trivy_run", func(t *testing.T) {
t.Parallel()
c = c.Pipeline("test_actionlint_run")
c = c.Pipeline("test_trivy_run")
require.NotNil(t, c)

_, err := linting.T(c, id).
WithNewFile(".trivyignore", dagger.ContainerWithNewFileOpts{
Contents: "AVD-DS-0002",
}).
WithNewFile("Dockerfile.test", dagger.ContainerWithNewFileOpts{
Contents: "FROM docker.io/library/alpine:$VARIANT\nHEALTHCHECK none",
}).
WithExec([]string{"sh", "-c", "/trivy config --severity=MEDIUM,HIGH,CRITICAL --exit-code=1 $(find . -type f \\( -name Dockerfile -o -name Dockerfile.* \\))"}).
Stdout(ctx)
require.NoError(t, err)
})
t.Run("Test_trivy_run_error", func(t *testing.T) {
t.Parallel()
c = c.Pipeline("test_trivy_run_error")
require.NotNil(t, c)

_, err := linting.T(c, id).
Expand Down
35 changes: 21 additions & 14 deletions cc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,27 @@ func TestMain(m *testing.M) {
func TestCodeQualityFunctions(t *testing.T) {
t.Parallel()

// t.Run("Test_trivy_function", func(t *testing.T) {
// t.Parallel()
// c = c.Pipeline("test_trivy_function")
// require.NotNil(t, c)

// dir, err := os.Getwd()
// require.NoError(t, err)
// require.NotEmpty(t, dir)
// require.IsType(t, "", dir)

// mountedDir := "/mountedtmp"
// err = linting.Trivy(dir, c, id, mountedDir)
// require.NoError(t, err)
// })
t.Run("Test_trivy_function", func(t *testing.T) {
t.Parallel()
c = c.Pipeline("test_trivy_function")
require.NotNil(t, c)

dir, err := os.Getwd()
require.NoError(t, err)
require.NotEmpty(t, dir)
require.IsType(t, "", dir)

mountedDir := "/mountedtmp"
p := filepath.Join(dir, "..")
require.NotEmpty(t, p)

id, err := util.MountedHostDirectory(c, id, p, mountedDir).
ID(context.Background())
require.NoError(t, err)

err = linting.Trivy(c, id)
require.NoError(t, err)
})
t.Run("Test_hadolint_function", func(t *testing.T) {
t.Parallel()
c = c.Pipeline("test_hadolint_function")
Expand Down

0 comments on commit 0920bbc

Please sign in to comment.