From 8db46c36c82ed74c6e5fcb2df5e324f0abbbc885 Mon Sep 17 00:00:00 2001 From: Ali Ok Date: Mon, 18 Nov 2019 12:09:40 +0300 Subject: [PATCH 1/2] Add version consistency test --- version/version.go | 2 +- version/version_test.go | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 version/version_test.go diff --git a/version/version.go b/version/version.go index aeb15892..f6c8e96f 100644 --- a/version/version.go +++ b/version/version.go @@ -2,5 +2,5 @@ package version var ( // Version is the version that will be applied to the KnativeServing resource. - Version = "0.10.0" + Version = "0.10.1" ) diff --git a/version/version_test.go b/version/version_test.go new file mode 100644 index 00000000..35cd4efd --- /dev/null +++ b/version/version_test.go @@ -0,0 +1,51 @@ +/* +Copyright 2019 The Knative 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 version + +import ( + mf "github.com/jcrossley3/manifestival" + "knative.dev/eventing-operator/test/e2e" + "path/filepath" + "runtime" + "testing" +) + +func TestManifestVersionSame(t *testing.T) { + clients := e2e.Setup(t) + + _, b, _, _ := runtime.Caller(0) + m, err := mf.NewManifest(filepath.Join((filepath.Dir(b)+"/.."), "cmd/manager/kodata/knative-eventing/"), false, clients.Config) + if err != nil { + t.Fatal("Failed to load manifest", err) + } + + // example: v0.10.1 + expectedLabelValue := "v" + Version + + resources := m.Resources + + for _, resource := range resources { + v, found := resource.GetLabels()["eventing.knative.dev/release"] + if !found { + // label is missing for this resource. we cannot do the check. + continue + } + if v != expectedLabelValue { + t.Errorf("Version info in manifest and operator don't match. got: %v, want: %v. Resource GVK: %v, Resource name: %v", v, expectedLabelValue, + resource.GroupVersionKind(), resource.GetName()) + } + } +} From 797c25a40db7466baf78c59bcc346ff23f8fe115 Mon Sep 17 00:00:00 2001 From: Ali Ok Date: Mon, 18 Nov 2019 13:49:02 +0300 Subject: [PATCH 2/2] Don't use actual rest config in version consistency check --- version/version_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/version/version_test.go b/version/version_test.go index 35cd4efd..13fe3fc3 100644 --- a/version/version_test.go +++ b/version/version_test.go @@ -17,17 +17,14 @@ package version import ( mf "github.com/jcrossley3/manifestival" - "knative.dev/eventing-operator/test/e2e" "path/filepath" "runtime" "testing" ) func TestManifestVersionSame(t *testing.T) { - clients := e2e.Setup(t) - _, b, _, _ := runtime.Caller(0) - m, err := mf.NewManifest(filepath.Join((filepath.Dir(b)+"/.."), "cmd/manager/kodata/knative-eventing/"), false, clients.Config) + resources, err := mf.Parse(filepath.Join(filepath.Dir(b)+"/..", "cmd/manager/kodata/knative-eventing/"), false) if err != nil { t.Fatal("Failed to load manifest", err) } @@ -35,8 +32,6 @@ func TestManifestVersionSame(t *testing.T) { // example: v0.10.1 expectedLabelValue := "v" + Version - resources := m.Resources - for _, resource := range resources { v, found := resource.GetLabels()["eventing.knative.dev/release"] if !found {