github.com/mccv1r0/cni@v0.7.0-alpha1/pkg/invoke/args_test.go (about) 1 // Copyright 2017 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 "os" 19 20 "github.com/containernetworking/cni/pkg/invoke" 21 22 . "github.com/onsi/ginkgo" 23 . "github.com/onsi/gomega" 24 ) 25 26 var _ = Describe("Args", func() { 27 Describe("AsEnv", func() { 28 It("places the CNI_ environment variables ahead of any ambient variables", func() { 29 args := invoke.Args{ 30 Command: "ADD", 31 ContainerID: "some-container-id", 32 NetNS: "/some/netns/path", 33 PluginArgs: [][2]string{ 34 {"KEY1", "VALUE1"}, 35 {"KEY2", "VALUE2"}, 36 }, 37 IfName: "eth7", 38 Path: "/some/cni/path", 39 } 40 const numCNIEnvVars = 6 41 42 latentVars := os.Environ() 43 44 cniEnv := args.AsEnv() 45 Expect(cniEnv).To(HaveLen(len(latentVars) + numCNIEnvVars)) 46 Expect(cniEnv[0:numCNIEnvVars]).To(Equal([]string{ 47 "CNI_COMMAND=ADD", 48 "CNI_CONTAINERID=some-container-id", 49 "CNI_NETNS=/some/netns/path", 50 "CNI_ARGS=KEY1=VALUE1;KEY2=VALUE2", 51 "CNI_IFNAME=eth7", 52 "CNI_PATH=/some/cni/path", 53 })) 54 55 for i := range latentVars { 56 Expect(cniEnv[numCNIEnvVars+i]).To(Equal(latentVars[i])) 57 } 58 }) 59 }) 60 })