Debian Codegraph @

pkg/version/reconcile_test.go

raw
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 version_test
16
17 import (
18 . "github.com/onsi/ginkgo/v2"
19 . "github.com/onsi/gomega"
20
21 "github.com/containernetworking/cni/pkg/version"
22 )
23
24 var _ = Describe("Reconcile versions of net config with versions supported by plugins", func() {
25 var (
26 reconciler *version.Reconciler
27 pluginInfo version.PluginInfo
28 )
29
30 BeforeEach(func() {
31 reconciler = &version.Reconciler{}
32 pluginInfo = version.PluginSupports("1.2.3", "4.3.2")
33 })
34
35 It("succeeds if the config version is supported by the plugin", func() {
36 err := reconciler.Check("4.3.2", pluginInfo)
37 Expect(err).NotTo(HaveOccurred())
38 })
39
40 Context("when the config version is not supported by the plugin", func() {
41 It("returns a helpful error", func() {
42 err := reconciler.Check("0.1.0", pluginInfo)
43
44 Expect(err).To(Equal(&version.ErrorIncompatible{
45 Config: "0.1.0",
46 Supported: []string{"1.2.3", "4.3.2"},
47 }))
48
49 Expect(err.Error()).To(Equal(`incompatible CNI versions: config is "0.1.0", plugin supports ["1.2.3" "4.3.2"]`))
50 })
51 })
52 })