libcni conf: support .json file extension
authorJulien Balestra <julien.balestra@blablacar.com>
Wed, 23 Nov 2016 09:46:17 +0000 (10:46 +0100)
committerJulien Balestra <julien.balestra@blablacar.com>
Wed, 23 Nov 2016 09:48:32 +0000 (10:48 +0100)
Content of the files are json, the configuration load should support .json

libcni/conf.go
libcni/conf_test.go

index 984b159..708686e 100644 (file)
@@ -55,7 +55,8 @@ func ConfFiles(dir string) ([]string, error) {
                if f.IsDir() {
                        continue
                }
-               if filepath.Ext(f.Name()) == ".conf" {
+               fileExt := filepath.Ext(f.Name())
+               if fileExt == ".conf" || fileExt == ".json" {
                        confFiles = append(confFiles, filepath.Join(dir, f.Name()))
                }
        }
index acbbfc0..4d032ba 100644 (file)
@@ -69,6 +69,22 @@ var _ = Describe("Loading configuration from disk", func() {
                        })
                })
 
+               Context("when the config file is .json extension instead of .conf", func() {
+                       BeforeEach(func() {
+                               Expect(os.Remove(configDir + "/50-whatever.conf")).To(Succeed())
+                               pluginConfig = []byte(`{ "name": "some-plugin", "some-key": "some-value" }`)
+                               Expect(ioutil.WriteFile(filepath.Join(configDir, "50-whatever.json"), pluginConfig, 0600)).To(Succeed())
+                       })
+                       It("finds the network config file for the plugin of the given type", func() {
+                               netConfig, err := libcni.LoadConf(configDir, "some-plugin")
+                               Expect(err).NotTo(HaveOccurred())
+                               Expect(netConfig).To(Equal(&libcni.NetworkConfig{
+                                       Network: &types.NetConf{Name: "some-plugin"},
+                                       Bytes:   pluginConfig,
+                               }))
+                       })
+               })
+
                Context("when there is no config for the desired plugin", func() {
                        It("returns a useful error", func() {
                                _, err := libcni.LoadConf(configDir, "some-other-plugin")