-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E tests for versioned-explicit-ref annotation. Refactoring for legi…
…bility.
Showing
3 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2020 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
uitest "github.com/cppforlife/go-cli-ui/ui/test" | ||
) | ||
|
||
func TestVersionedExplicitReference(t *testing.T) { | ||
env := BuildEnv(t) | ||
logger := Logger{} | ||
kapp := Kapp{t, env.Namespace, env.KappBinaryPath, logger} | ||
|
||
yaml1 := ` | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: config-1 | ||
annotations: | ||
kapp.k14s.io/versioned: "" | ||
data: | ||
foo: bar | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: config-2 | ||
annotations: | ||
kapp.k14s.io/versioned-explicit-ref: '{ "references": [ { "namespace": "kapp-test", "kind" : "ConfigMap", "name": "config-1"} ] }' | ||
data: | ||
foo: bar | ||
` | ||
|
||
yaml2 := ` | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: config-1 | ||
annotations: | ||
kapp.k14s.io/versioned: "" | ||
data: | ||
foo: alpha | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: config-2 | ||
annotations: | ||
kapp.k14s.io/versioned-explicit-ref: '{ "references": [ { "namespace": "kapp-test", "kind" : "ConfigMap", "name": "config-1"} ] }' | ||
data: | ||
foo: bar | ||
` | ||
|
||
name := "test-versioned-explicit-references" | ||
cleanUp := func() { | ||
kapp.Run([]string{"delete", "-a", name}) | ||
} | ||
|
||
cleanUp() | ||
defer cleanUp() | ||
|
||
logger.Section("deploy initial", func() { | ||
kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name}, | ||
RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml1)}) | ||
}) | ||
|
||
logger.Section("update versioned resource", func() { | ||
out, _ := kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name, "--json"}, | ||
RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml2)}) | ||
resp := uitest.JSONUIFromBytes(t, []byte(out)) | ||
|
||
expected := []map[string]string{{ | ||
"age": "", | ||
"conditions": "", | ||
"kind": "ConfigMap", | ||
"name": "config-1-ver-2", | ||
"namespace": "kapp-test", | ||
"op": "create", | ||
"op_strategy": "", | ||
"reconcile_info": "", | ||
"reconcile_state": "", | ||
"wait_to": "reconcile", | ||
}, { | ||
"age": "<replaced>", | ||
"conditions": "", | ||
"kind": "ConfigMap", | ||
"name": "config-2", | ||
"namespace": "kapp-test", | ||
"op": "update", | ||
"op_strategy": "", | ||
"reconcile_info": "", | ||
"reconcile_state": "ok", | ||
"wait_to": "reconcile", | ||
}} | ||
|
||
if !reflect.DeepEqual(replaceAge(resp.Tables[0].Rows), expected) { | ||
t.Fatalf("Expected to see correct changes, but did not: '%s'", out) | ||
} | ||
}) | ||
} |