Skip to content

Commit

Permalink
test: Add tests for Hadolint with custom configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaredevelop committed Aug 15, 2024
1 parent 3813fda commit 1678fef
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions hadolint/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,44 @@ func Test_Hadolint(t *testing.T) {
t.Parallel()
ctx := context.Background()

t.Run("Test_hadolint_with_config", func(t *testing.T) {
t.Parallel()
container := base()
require.NotNil(t, container)

_, err := container.
WithMountedDirectory("/tmp", c.Host().Directory("./test/testdata")).
WithWorkdir("/tmp").
// WithMountedFile("/.config/.hadolint.yaml", c.Host().Directory("./test/testdata").File(".config/hadolint.yaml")).
WithMountedFile("/.config/.hadolint.yaml", c.Host().File("./test/testdata/.config/.hadolint.yaml")).
WithExec([]string{"sh", "-c", "find . -type f \\( -name Dockerfile -o -name Dockerfile.* \\) -print0 | xargs -0 hadolint --config /.config/.hadolint.yaml"}).
Stdout(ctx)
require.Error(t, err)
errorIDs := []string{"DL3006", "DL3008"}
for _, id := range errorIDs {
require.Contains(t, err.Error(), id)
}
errorIDs = []string{"DL3015", "DL3014"}
for _, id := range errorIDs {
require.NotContains(t, err.Error(), id)
}
})
t.Run("Test_hadolint_dockerfile_error", func(t *testing.T) {
t.Parallel()
container := base()
require.NotNil(t, container)

_, err := container.
WithMountedDirectory("/tmp", c.Host().Directory("./test/testdata")).
WithWorkdir("/tmp").
WithExec([]string{"sh", "-c", "find . -type f \\( -name Dockerfile -o -name Dockerfile.* \\) -print0 | xargs -0 hadolint"}).
Stdout(ctx)
require.Error(t, err)
errorIDs := []string{"DL3006", "DL3008"}
for _, id := range errorIDs {
require.Contains(t, err.Error(), id)
}
})
t.Run("Test_hadolint_error", func(t *testing.T) {
t.Parallel()
container := base()
Expand Down

0 comments on commit 1678fef

Please sign in to comment.