From 1678fef383f97cbbff309e55d3bb5c9fdbd68139 Mon Sep 17 00:00:00 2001 From: softwaredevelop <61334390+softwaredevelop@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:22:01 +0200 Subject: [PATCH] test: Add tests for Hadolint with custom configuration --- hadolint/main_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hadolint/main_test.go b/hadolint/main_test.go index 369e29f..9cea49c 100644 --- a/hadolint/main_test.go +++ b/hadolint/main_test.go @@ -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()