github.com/mccv1r0/cni@v0.7.0-alpha1/pkg/invoke/get_version_integration_test.go (about) 1 // Copyright 2016 CNI authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package invoke_test 16 17 import ( 18 "io/ioutil" 19 "os" 20 "path/filepath" 21 "runtime" 22 23 "github.com/containernetworking/cni/pkg/invoke" 24 "github.com/containernetworking/cni/pkg/version" 25 "github.com/containernetworking/cni/pkg/version/testhelpers" 26 27 . "github.com/onsi/ginkgo" 28 . "github.com/onsi/ginkgo/extensions/table" 29 . "github.com/onsi/gomega" 30 ) 31 32 var _ = Describe("GetVersion, integration tests", func() { 33 var ( 34 pluginDir string 35 pluginPath string 36 ) 37 38 BeforeEach(func() { 39 pluginDir, err := ioutil.TempDir("", "plugins") 40 Expect(err).NotTo(HaveOccurred()) 41 pluginPath = filepath.Join(pluginDir, "test-plugin") 42 if runtime.GOOS == "windows" { 43 pluginPath += ".exe" 44 } 45 }) 46 47 AfterEach(func() { 48 Expect(os.RemoveAll(pluginDir)).To(Succeed()) 49 }) 50 51 DescribeTable("correctly reporting plugin versions", 52 func(gitRef string, pluginSource string, expectedVersions version.PluginInfo) { 53 Expect(testhelpers.BuildAt([]byte(pluginSource), gitRef, pluginPath)).To(Succeed()) 54 versionInfo, err := invoke.GetVersionInfo(pluginPath, nil) 55 Expect(err).NotTo(HaveOccurred()) 56 57 Expect(versionInfo.SupportedVersions()).To(ConsistOf(expectedVersions.SupportedVersions())) 58 }, 59 60 Entry("historical: before VERSION was introduced", 61 git_ref_v010, plugin_source_no_custom_versions, 62 version.PluginSupports("0.1.0"), 63 ), 64 65 Entry("historical: when VERSION was introduced but plugins couldn't customize it", 66 git_ref_v020_no_custom_versions, plugin_source_no_custom_versions, 67 version.PluginSupports("0.1.0", "0.2.0"), 68 ), 69 70 Entry("historical: when plugins started reporting their own version list", 71 git_ref_v020_custom_versions, plugin_source_v020_custom_versions, 72 version.PluginSupports("0.2.0", "0.999.0"), 73 ), 74 75 Entry("historical: before GET was introduced", 76 git_ref_v031, plugin_source_v020_custom_versions, 77 version.PluginSupports("0.2.0", "0.999.0"), 78 ), 79 80 // this entry tracks the current behavior. Before you change it, ensure 81 // that its previous behavior is captured in the most recent "historical" entry 82 Entry("current", 83 "HEAD", plugin_source_v040_get, 84 version.PluginSupports("0.2.0", "0.4.0", "0.999.0"), 85 ), 86 ) 87 }) 88 89 // A 0.4.0 plugin that supports GET 90 const plugin_source_v040_get = `package main 91 92 import ( 93 "github.com/containernetworking/cni/pkg/skel" 94 "github.com/containernetworking/cni/pkg/version" 95 "fmt" 96 ) 97 98 func c(_ *skel.CmdArgs) error { fmt.Println("{}"); return nil } 99 100 func main() { skel.PluginMain(c, c, c, version.PluginSupports("0.2.0", "0.4.0", "0.999.0"), "") } 101 ` 102 103 const git_ref_v031 = "909fe7d" 104 105 // a 0.2.0 plugin that can report its own versions 106 const plugin_source_v020_custom_versions = `package main 107 108 import ( 109 "github.com/containernetworking/cni/pkg/skel" 110 "github.com/containernetworking/cni/pkg/version" 111 "fmt" 112 ) 113 114 func c(_ *skel.CmdArgs) error { fmt.Println("{}"); return nil } 115 116 func main() { skel.PluginMain(c, c, version.PluginSupports("0.2.0", "0.999.0")) } 117 ` 118 const git_ref_v020_custom_versions = "bf31ed15" 119 120 // a minimal 0.1.0 / 0.2.0 plugin that cannot report it's own version support 121 const plugin_source_no_custom_versions = `package main 122 123 import "github.com/containernetworking/cni/pkg/skel" 124 import "fmt" 125 126 func c(_ *skel.CmdArgs) error { fmt.Println("{}"); return nil } 127 128 func main() { skel.PluginMain(c, c) } 129 ` 130 131 const git_ref_v010 = "2c482f4" 132 const git_ref_v020_no_custom_versions = "349d66d"