From d4f4e976e6e39bfd879b1b591d8a5a9f548c248a Mon Sep 17 00:00:00 2001 From: Xenia Lisovskaia Date: Mon, 3 Dec 2018 03:40:36 -0400 Subject: [PATCH 1/3] add templates test verification testcase --- tests/templates_verification_test.go | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/templates_verification_test.go diff --git a/tests/templates_verification_test.go b/tests/templates_verification_test.go new file mode 100644 index 000000000..72ed32d70 --- /dev/null +++ b/tests/templates_verification_test.go @@ -0,0 +1,82 @@ +/* + * This file is part of the KubeVirt project + * + * 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. + * + * Copyright 2018 Red Hat, Inc. + * + */ + +package tests_test + +import ( + "flag" + "strings" + "net/http" + "io/ioutil" + "regexp" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "kubevirt.io/kubevirt/tests" +) + +func search_for_pattern(yaml_segment string, pattern string) bool { + r, _ := regexp.Compile(pattern) + for _, line := range strings.Split(yaml_segment, "\n") { + if r.MatchString(line) { + return true + } + } + return false +} + +var _ = Describe("Common templates", func() { + flag.Parse() + + BeforeEach(func() { + tests.BeforeTestCleanup() + }) + + Context("Testing generated templates", func() { + + // CNV-1069 + It("Check if template valid for UI", func() { + + // Getting common_templates + // TODO: replace downloading common-templates with getting common-templates from RPM + ct_yml_url := "https://github.com/kubevirt/common-templates/releases/download/v0.3.1/common-templates-v0.3.1.yaml" + response, err := http.Get(ct_yml_url) + Expect(err).NotTo(HaveOccurred()) + defer response.Body.Close() + data, err := ioutil.ReadAll(response.Body) + common_templates_yaml := string(data) + + for _, yaml_segment := range strings.Split(common_templates_yaml, "\n---\n") { + + if !search_for_pattern(yaml_segment, "^Kind: Template$") { + continue + } + + By("Checking that template contains required lables") + Expect(search_for_pattern(yaml_segment, "\\s+os.template.cnv.io/[a-z0-9\\.]+:\\s\"true\"$")).To(BeTrue(), "Template should have os label") + Expect(search_for_pattern(yaml_segment, "\\s+workload.template.cnv.io/[a-z]+:\\s\"true\"$")).To(BeTrue(), "Template should have workload label") + Expect(search_for_pattern(yaml_segment, "\\s+flavor.template.cnv.io/[a-z]+:\\s\"true\"$")).To(BeTrue(), "Template should have flavor label") + Expect(search_for_pattern(yaml_segment, "\\s+template.cnv.io/type:\\s\"base\"$")).To(BeTrue(), "Template should have type base") + + } + }) + }) +}) + From ec135c6c9e3a9ccf136da8d2311569521ce3ec04 Mon Sep 17 00:00:00 2001 From: Xenia Lisovskaia Date: Sat, 29 Dec 2018 12:51:27 -0400 Subject: [PATCH 2/3] rebase & implement determination of the manifest-s latest version --- tests/templates_verification_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/templates_verification_test.go b/tests/templates_verification_test.go index 72ed32d70..f32e52c41 100644 --- a/tests/templates_verification_test.go +++ b/tests/templates_verification_test.go @@ -30,6 +30,8 @@ import ( . "github.com/onsi/gomega" "kubevirt.io/kubevirt/tests" + "os/exec" + ) func search_for_pattern(yaml_segment string, pattern string) bool { @@ -56,7 +58,10 @@ var _ = Describe("Common templates", func() { // Getting common_templates // TODO: replace downloading common-templates with getting common-templates from RPM - ct_yml_url := "https://github.com/kubevirt/common-templates/releases/download/v0.3.1/common-templates-v0.3.1.yaml" + + ct_yml_url_byte, err := exec.Command("/bin/bash", "-c", "curl -s https://api.github.com/repos/kubevirt/common-templates/releases/latest | grep browser_download_url | cut -d '\"' -f 4").Output() + ct_yml_url := string(ct_yml_url_byte) + Expect(err).ToNot(HaveOccurred()) response, err := http.Get(ct_yml_url) Expect(err).NotTo(HaveOccurred()) defer response.Body.Close() From 20865d3091abe8c22187a10ece477d499bf623aa Mon Sep 17 00:00:00 2001 From: Xenia Lisovskaia Date: Wed, 9 Jan 2019 10:48:43 -0400 Subject: [PATCH 3/3] running make generate --- tests/templates_verification_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/templates_verification_test.go b/tests/templates_verification_test.go index f32e52c41..91b2145e9 100644 --- a/tests/templates_verification_test.go +++ b/tests/templates_verification_test.go @@ -21,17 +21,16 @@ package tests_test import ( "flag" - "strings" - "net/http" "io/ioutil" + "net/http" "regexp" + "strings" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "kubevirt.io/kubevirt/tests" - "os/exec" - + "os/exec" ) func search_for_pattern(yaml_segment string, pattern string) bool { @@ -59,9 +58,9 @@ var _ = Describe("Common templates", func() { // Getting common_templates // TODO: replace downloading common-templates with getting common-templates from RPM - ct_yml_url_byte, err := exec.Command("/bin/bash", "-c", "curl -s https://api.github.com/repos/kubevirt/common-templates/releases/latest | grep browser_download_url | cut -d '\"' -f 4").Output() - ct_yml_url := string(ct_yml_url_byte) - Expect(err).ToNot(HaveOccurred()) + ct_yml_url_byte, err := exec.Command("/bin/bash", "-c", "curl -s https://api.github.com/repos/kubevirt/common-templates/releases/latest | grep browser_download_url | cut -d '\"' -f 4").Output() + ct_yml_url := string(ct_yml_url_byte) + Expect(err).ToNot(HaveOccurred()) response, err := http.Get(ct_yml_url) Expect(err).NotTo(HaveOccurred()) defer response.Body.Close() @@ -84,4 +83,3 @@ var _ = Describe("Common templates", func() { }) }) }) -