forked from GoogleContainerTools/skaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagnose_test.go
115 lines (99 loc) · 2.99 KB
/
diagnose_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
Copyright 2019 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package integration
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"text/template"
"github.com/GoogleContainerTools/skaffold/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/testutil"
)
func TestDiagnose(t *testing.T) {
MarkIntegrationTest(t, CanRunWithoutGcp)
examples, err := folders("examples")
failNowIfError(t, err)
if len(examples) == 0 {
t.Fatal("didn't find any example")
}
for _, example := range examples {
t.Run(example, func(t *testing.T) {
dir := filepath.Join("examples", example)
if _, err := os.Stat(filepath.Join(dir, "skaffold.yaml")); os.IsNotExist(err) {
t.Skip("skipping diagnose in " + dir)
}
skaffold.Diagnose().InDir(dir).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
}
func TestMultiConfigDiagnose(t *testing.T) {
MarkIntegrationTest(t, CanRunWithoutGcp)
tests := []struct {
description string
dir string
cpSkaffold bool
}{
{
description: "single skaffold.yaml outside of source dir",
dir: "testdata/diagnose/temp-config",
cpSkaffold: true,
},
{
description: "multi skaffold.yaml outside of source dir",
dir: "testdata/diagnose/multi-config",
cpSkaffold: true,
},
{
description: "multi skaffold.yaml",
dir: "testdata/diagnose/multi-config",
cpSkaffold: false,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
args := []string{}
if test.cpSkaffold {
tmpDir := t.NewTempDir()
configContents, err := ioutil.ReadFile(filepath.Join(test.dir, "skaffold.yaml"))
t.CheckNoError(err)
tmpDir.Write("skaffold.yaml", string(configContents))
args = append(args, fmt.Sprintf("-f=%s", tmpDir.Path("skaffold.yaml")))
}
out := skaffold.Diagnose(append(args, "--yaml-only")...).InDir(test.dir).RunOrFailOutput(t.T)
templ, err := ioutil.ReadFile(filepath.Join(test.dir, "diagnose.tmpl"))
t.CheckNoError(err)
outTemplate := template.Must(template.New("tmpl").Parse(string(templ)))
cwd, err := filepath.Abs(test.dir)
t.CheckNoError(err)
expected := &bytes.Buffer{}
outTemplate.Execute(expected, map[string]string{"Root": cwd})
t.CheckDeepEqual(expected.String(), string(out))
})
}
}