Debian Codegraph @

pkg/invoke/get_version_integration_test.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 "context"
19 "os"
20 "path/filepath"
21 "runtime"
22
23 . "github.com/onsi/ginkgo/v2"
24 . "github.com/onsi/gomega"
25
26 "github.com/containernetworking/cni/pkg/invoke"
27 "github.com/containernetworking/cni/pkg/version"
28 "github.com/containernetworking/cni/pkg/version/testhelpers"
29 )
30
31 var _ = Describe("GetVersion, integration tests", func() {
32 var (
33 pluginDir string
34 pluginPath string
35 )
36
37 BeforeEach(func() {
38 pluginDir, err := os.MkdirTemp("", "plugins")
39 Expect(err).NotTo(HaveOccurred())
40 pluginPath = filepath.Join(pluginDir, "test-plugin")
41 if runtime.GOOS == "windows" {
42 pluginPath += ".exe"
43 }
44 })
45
46 AfterEach(func() {
47 Expect(os.RemoveAll(pluginDir)).To(Succeed())
48 })
49
50 DescribeTable("correctly reporting plugin versions",
51 func(gitRef string, pluginSource string, expectedVersions version.PluginInfo) {
52 Expect(testhelpers.BuildAt([]byte(pluginSource), gitRef, pluginPath)).To(Succeed())
53 versionInfo, err := invoke.GetVersionInfo(context.TODO(), pluginPath, nil)
54 Expect(err).NotTo(HaveOccurred())
55
56 Expect(versionInfo.SupportedVersions()).To(ConsistOf(expectedVersions.SupportedVersions()))
57 },
58
59 Entry("historical: before VERSION was introduced",
60 git_ref_v010, plugin_source_no_custom_versions,
61 version.PluginSupports("0.1.0"),
62 ),
63
64 Entry("historical: when VERSION was introduced but plugins couldn't customize it",
65 git_ref_v020_no_custom_versions, plugin_source_no_custom_versions,
66 version.PluginSupports("0.1.0", "0.2.0"),
67 ),
68
69 Entry("historical: when plugins started reporting their own version list",
70 git_ref_v020_custom_versions, plugin_source_v020_custom_versions,
71 version.PluginSupports("0.2.0", "0.999.0"),
72 ),
73
74 Entry("historical: before CHECK was introduced",
75 git_ref_v031, plugin_source_v020_custom_versions,
76 version.PluginSupports("0.2.0", "0.999.0"),
77 ),
78
79 // this entry tracks the current behavior. Before you change it, ensure
80 // that its previous behavior is captured in the most recent "historical" entry
81 Entry("current",
82 "HEAD", plugin_source_v040_check,
83 version.PluginSupports("0.2.0", "0.4.0", "0.999.0"),
84 ),
85 )
86 })
87
88 // A 0.4.0 plugin that supports CHECK
89 const plugin_source_v040_check = `package main
90
91 import (
92 "github.com/containernetworking/cni/pkg/skel"
93 "github.com/containernetworking/cni/pkg/version"
94 "fmt"
95 )
96
97 func c(_ *skel.CmdArgs) error { fmt.Println("{}"); return nil }
98
99 func main() { skel.PluginMain(c, c, c, version.PluginSupports("0.2.0", "0.4.0", "0.999.0"), "") }
100 `
101
102 const git_ref_v031 = "909fe7d"
103
104 // a 0.2.0 plugin that can report its own versions
105 const plugin_source_v020_custom_versions = `package main
106
107 import (
108 "github.com/containernetworking/cni/pkg/skel"
109 "github.com/containernetworking/cni/pkg/version"
110 "fmt"
111 )
112
113 func c(_ *skel.CmdArgs) error { fmt.Println("{}"); return nil }
114
115 func main() { skel.PluginMain(c, c, version.PluginSupports("0.2.0", "0.999.0")) }
116 `
117 const git_ref_v020_custom_versions = "bf31ed15"
118
119 // a minimal 0.1.0 / 0.2.0 plugin that cannot report it's own version support
120 const plugin_source_no_custom_versions = `package main
121
122 import "github.com/containernetworking/cni/pkg/skel"
123 import "fmt"
124
125 func c(_ *skel.CmdArgs) error { fmt.Println("{}"); return nil }
126
127 func main() { skel.PluginMain(c, c) }
128 `
129
130 const (
131 git_ref_v010 = "2c482f4"
132 git_ref_v020_no_custom_versions = "349d66d"
133 )