mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
fix the failed test
This commit is contained in:
parent
beacc87ebf
commit
f55d87ab61
@ -569,7 +569,93 @@ func TestDirectoryBuilder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupKustomizeDirectory() (string, error) {
|
||||||
|
path, err := ioutil.TempDir("/tmp", "")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
contents := map[string]string{
|
||||||
|
"configmap.yaml": `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: the-map
|
||||||
|
data:
|
||||||
|
altGreeting: "Good Morning!"
|
||||||
|
enableRisky: "false"
|
||||||
|
`,
|
||||||
|
"deployment.yaml": `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: the-deployment
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
deployment: hello
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: the-container
|
||||||
|
image: monopole/hello:1
|
||||||
|
command: ["/hello",
|
||||||
|
"--port=8080",
|
||||||
|
"--enableRiskyFeature=$(ENABLE_RISKY)"]
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
- name: ALT_GREETING
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: the-map
|
||||||
|
key: altGreeting
|
||||||
|
- name: ENABLE_RISKY
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: the-map
|
||||||
|
key: enableRisky
|
||||||
|
`,
|
||||||
|
"service.yaml": `
|
||||||
|
kind: Service
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
name: the-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
deployment: hello
|
||||||
|
type: LoadBalancer
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 8666
|
||||||
|
targetPort: 8080
|
||||||
|
`,
|
||||||
|
"kustomization.yaml": `
|
||||||
|
nameprefix: test-
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
- service.yaml
|
||||||
|
- configmap.yaml
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
for filename, content := range contents {
|
||||||
|
err = ioutil.WriteFile(filepath.Join(path, filename), []byte(content), 0660)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestKustomizeDirectoryBuilder(t *testing.T) {
|
func TestKustomizeDirectoryBuilder(t *testing.T) {
|
||||||
|
dir, err := setupKustomizeDirectory()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
directory string
|
directory string
|
||||||
expectErr bool
|
expectErr bool
|
||||||
@ -582,12 +668,11 @@ func TestKustomizeDirectoryBuilder(t *testing.T) {
|
|||||||
expectErr: true,
|
expectErr: true,
|
||||||
errMsg: "No kustomization file found",
|
errMsg: "No kustomization file found",
|
||||||
},
|
},
|
||||||
// TODO(Liujingfang1): Fix this test in bazel test
|
{
|
||||||
//{
|
directory: dir,
|
||||||
// directory: "../../../artifacts/kustomization",
|
expectErr: false,
|
||||||
// expectErr: false,
|
expectedNames: []string{"test-the-map", "test-the-deployment", "test-the-service"},
|
||||||
// expectedNames: []string{"test-the-map", "test-the-deployment", "test-the-service"},
|
},
|
||||||
//},
|
|
||||||
{
|
{
|
||||||
directory: "../../../artifacts/kustomization/should-not-load.yaml",
|
directory: "../../../artifacts/kustomization/should-not-load.yaml",
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user