add test for ensuring initial subnet creation does not contain an error
authorEvan Hazlett <ejhazlett@gmail.com>
Thu, 2 Mar 2017 20:16:09 +0000 (15:16 -0500)
committerEvan Hazlett <ejhazlett@gmail.com>
Thu, 2 Mar 2017 20:16:09 +0000 (15:16 -0500)
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
plugins/ipam/host-local/host_local_suite_test.go [new file with mode: 0644]
plugins/ipam/host-local/host_local_test.go

diff --git a/plugins/ipam/host-local/host_local_suite_test.go b/plugins/ipam/host-local/host_local_suite_test.go
new file mode 100644 (file)
index 0000000..1867ef7
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2016 CNI authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+       . "github.com/onsi/ginkgo"
+       . "github.com/onsi/gomega"
+
+       "testing"
+)
+
+func TestHostLocal(t *testing.T) {
+       RegisterFailHandler(Fail)
+       RunSpecs(t, "HostLocal Suite")
+}
index 52b1c79..e6b690f 100644 (file)
@@ -216,4 +216,39 @@ var _ = Describe("host-local Operations", func() {
                _, err = os.Stat(ipFilePath)
                Expect(err).To(HaveOccurred())
        })
+
+       It("does not output an error message upon initial subnet creation", func() {
+               const ifname string = "eth0"
+               const nspath string = "/some/where"
+
+               tmpDir, err := ioutil.TempDir("", "host_local_artifacts")
+               Expect(err).NotTo(HaveOccurred())
+               defer os.RemoveAll(tmpDir)
+
+               conf := fmt.Sprintf(`{
+    "cniVersion": "0.2.0",
+    "name": "mynet",
+    "type": "ipvlan",
+    "master": "foo0",
+    "ipam": {
+        "type": "host-local",
+        "subnet": "10.1.2.0/24",
+        "dataDir": "%s"
+    }
+}`, tmpDir)
+
+               args := &skel.CmdArgs{
+                       ContainerID: "testing",
+                       Netns:       nspath,
+                       IfName:      ifname,
+                       StdinData:   []byte(conf),
+               }
+
+               // Allocate the IP
+               _, out, err := testutils.CmdAddWithResult(nspath, ifname, []byte(conf), func() error {
+                       return cmdAdd(args)
+               })
+               Expect(err).NotTo(HaveOccurred())
+               Expect(strings.Index(string(out), "Error retriving last reserved ip")).To(Equal(-1))
+       })
 })