Fix api tests that accomodated bad label and anno quoting.

This commit is contained in:
monopole
2021-01-15 17:36:39 -08:00
parent cb59e0ef5f
commit cb42142161
4 changed files with 30 additions and 40 deletions

View File

@@ -29,6 +29,8 @@ metadata:
Filters: []kio.Filter{Filter{
Annotations: map[string]string{
"foo": "bar",
"booleanValue": "true",
"numberValue": "42",
},
FsSlice: fss,
}},
@@ -44,12 +46,16 @@ metadata:
// metadata:
// name: instance
// annotations:
// booleanValue: "true"
// foo: bar
// numberValue: "42"
// ---
// apiVersion: example.com/v1
// kind: Bar
// metadata:
// name: instance
// annotations:
// booleanValue: "true"
// foo: bar
// numberValue: "42"
}

View File

@@ -4,7 +4,6 @@
package krusty_test
import (
"fmt"
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
@@ -28,7 +27,8 @@ func TestBasicIO_1(t *testing.T) {
// return an error (that is then ignored by GetAnnotations)
// }
// The error happens when any annotation value can be interpreted as
// a boolean or number.
// a boolean or number. Such annotations cannot be successfully applied
// to an object in a cluster unless they are quoted.
t.SkipNow()
}
th.WriteK(".", `
@@ -49,6 +49,7 @@ spec:
`)
m := th.Run(".", opts)
// The annotations are sorted by key, hence the order change.
// Quotes are added intentionally.
th.AssertActualEqualsExpected(
m, `
apiVersion: v1
@@ -56,8 +57,8 @@ kind: Service
metadata:
annotations:
color: green
happy: true
port: 8080
happy: "true"
port: "8080"
name: demo
spec:
clusterIP: None
@@ -71,9 +72,7 @@ func TestBasicIO_2(t *testing.T) {
resources:
- service.yaml
`)
// All the annotation values are quoted.
// The apimachinery code path retains the quotes, the kyaml
// path drops them at the moment.
// All the annotation values are quoted in the input.
th.WriteF("service.yaml", `
apiVersion: v1
kind: Service
@@ -88,20 +87,16 @@ spec:
`)
m := th.Run(".", opts)
// The annotations are sorted by key, hence the order change.
expFmt := `
th.AssertActualEqualsExpected(m, `
apiVersion: v1
kind: Service
metadata:
annotations:
color: green
happy: %s
port: %s
happy: "true"
port: "8080"
name: demo
spec:
clusterIP: None
`
th.AssertActualEqualsExpected(
m, opts.IfApiMachineryElseKyaml(
fmt.Sprintf(expFmt, `"true"`, `"8080"`),
fmt.Sprintf(expFmt, `true`, `8080`)))
`)
}

View File

@@ -1,7 +1,6 @@
package krusty_test
import (
"fmt"
"os/exec"
"testing"
@@ -129,9 +128,8 @@ stringData:
bootcmd:
- mkdir /mnt/vda
`)
opts := th.MakeOptionsPluginsEnabled()
m := th.Run("/app", opts)
expFmt := `
m := th.Run("/app", th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
kind: Secret
metadata:
@@ -154,7 +152,7 @@ metadata:
name: demo
name: demo-budget
spec:
minAvailable: 67%%
minAvailable: 67%
selector:
matchLabels:
app: cockroachdb
@@ -187,7 +185,9 @@ metadata:
annotations:
config.kubernetes.io/path: config/demo_service.yaml
prometheus.io/path: _status/vars
%s
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
labels:
app: cockroachdb
name: demo
@@ -302,14 +302,7 @@ spec:
resources:
requests:
storage: 1Gi
`
th.AssertActualEqualsExpected(m, opts.IfApiMachineryElseKyaml(
fmt.Sprintf(expFmt, ` prometheus.io/port: "8080"
prometheus.io/scrape: "true"
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"`),
fmt.Sprintf(expFmt, ` prometheus.io/port: 8080
prometheus.io/scrape: true
service.alpha.kubernetes.io/tolerate-unready-endpoints: true`)))
`)
}
func TestFnContainerTransformer(t *testing.T) {

View File

@@ -757,9 +757,9 @@ kind: Service
metadata:
annotations:
prometheus.io/path: _status/vars
prometheus.io/port: %s
prometheus.io/scrape: %s
service.alpha.kubernetes.io/tolerate-unready-endpoints: %s
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
labels:
app: cockroachdb
name: dev-base-cockroachdb
@@ -929,12 +929,8 @@ metadata:
`
th.AssertActualEqualsExpected(m,
opts.IfApiMachineryElseKyaml(
fmt.Sprintf(
expFmt,
`"8080"`, `"true"`, `"true"`, `8080`, `8080`, `8080`, `8080`),
fmt.Sprintf(
expFmt,
`8080`, `true`, `true`, `"8080"`, `"8080"`, `"8080"`, `"8080"`),
fmt.Sprintf(expFmt, `8080`, `8080`, `8080`, `8080`),
fmt.Sprintf(expFmt, `"8080"`, `"8080"`, `"8080"`, `"8080"`),
))
}