Skip to content

Commit

Permalink
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
Browse files Browse the repository at this point in the history
100mik committed Sep 21, 2021
1 parent 69d2f7f commit 8d4ace3
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions test/e2e/versioned_explicit_reference_test.go
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: bar1
---
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)
}
})
}

0 comments on commit 8d4ace3

Please sign in to comment.