From 9e945d21bd7e53cfe5259a1e5b05f2c2fd7d5133 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 7 Oct 2019 09:18:42 +0200 Subject: [PATCH] Every type of artifact should be handled. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If that’s not the case, we want to see it fail during tests. Signed-off-by: David Gageot --- integration/diagnose_test.go | 42 +++++++++++++++++++++++---------- pkg/skaffold/runner/diagnose.go | 6 ++++- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/integration/diagnose_test.go b/integration/diagnose_test.go index 7d3740a745c..c334daec94b 100644 --- a/integration/diagnose_test.go +++ b/integration/diagnose_test.go @@ -17,6 +17,8 @@ limitations under the License. package integration import ( + "io/ioutil" + "path/filepath" "testing" "github.com/GoogleContainerTools/skaffold/integration/skaffold" @@ -30,20 +32,34 @@ func TestDiagnose(t *testing.T) { t.Skip("skipping test that is not gcp only") } - tests := []struct { - name string - dir string - }{ - {name: "kaniko builder", dir: "examples/kaniko"}, - {name: "docker builder", dir: "examples/nodejs"}, - {name: "jib maven builder", dir: "testdata/jib"}, - {name: "jib gradle builder", dir: "testdata/jib-gradle"}, - {name: "bazel builder", dir: "examples/bazel"}, - {name: "custom builder", dir: "testdata/custom"}, + examples, err := folders("examples") + if err != nil { + t.Fatal("unable to list examples") } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - skaffold.Diagnose().InDir(test.dir).RunOrFail(t) + if len(examples) == 0 { + t.Fatal("didn't find any example") + } + + for _, example := range examples { + t.Run(example, func(t *testing.T) { + skaffold.Diagnose().InDir(filepath.Join("examples", example)).RunOrFail(t) }) } } + +func folders(root string) ([]string, error) { + var folders []string + + files, err := ioutil.ReadDir(root) + if err != nil { + return nil, err + } + + for _, f := range files { + if f.Mode().IsDir() { + folders = append(folders, f.Name()) + } + } + + return folders, err +} diff --git a/pkg/skaffold/runner/diagnose.go b/pkg/skaffold/runner/diagnose.go index b58355d81c0..a57140c2b50 100644 --- a/pkg/skaffold/runner/diagnose.go +++ b/pkg/skaffold/runner/diagnose.go @@ -97,8 +97,12 @@ func typeOfArtifact(a *latest.Artifact) string { return "Bazel artifact" case a.JibArtifact != nil: return "Jib artifact" + case a.KanikoArtifact != nil: + return "Kaniko artifact" + case a.CustomArtifact != nil: + return "Custom artifact" default: - return "Unknown artifact" + panic("Unknown artifact") } }