Debian Codegraph @

pkg/invoke/get_version_integration_test.go

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