Windows compatibility: all tests pass!
authorGabriel Rosenhouse <grosenhouse@pivotal.io>
Mon, 23 Oct 2017 06:21:08 +0000 (23:21 -0700)
committerGabriel Rosenhouse <grosenhouse@pivotal.io>
Mon, 23 Oct 2017 06:21:08 +0000 (23:21 -0700)
libcni/api_test.go
libcni/backwards_compatibility_test.go
libcni/libcni_suite_test.go
pkg/invoke/get_version_integration_test.go
pkg/version/legacy_examples/examples.go
pkg/version/legacy_examples/legacy_examples_test.go
pkg/version/testhelpers/testhelpers_test.go
plugins/test/noop/noop_test.go

index 0616bf4..711ffc1 100644 (file)
@@ -72,7 +72,7 @@ func newPluginInfo(configValue, prevResult string, injectDebugFilePath bool, res
                config += fmt.Sprintf(`, "prevResult": %s`, prevResult)
        }
        if injectDebugFilePath {
-               config += fmt.Sprintf(`, "debugFile": "%s"`, debugFilePath)
+               config += fmt.Sprintf(`, "debugFile": %q`, debugFilePath)
        }
        if len(capabilities) > 0 {
                config += `, "capabilities": {`
index a1fcce5..4f4f65f 100644 (file)
@@ -19,6 +19,7 @@ import (
        "os"
        "os/exec"
        "path/filepath"
+       "runtime"
        "strings"
 
        "github.com/containernetworking/cni/libcni"
@@ -55,6 +56,9 @@ var _ = Describe("Backwards compatibility", func() {
        })
 
        It("correctly handles the request from a runtime with an older libcni", func() {
+               if runtime.GOOS == "windows" {
+                       Skip("cannot build old runtime on windows")
+               }
                example := legacy_examples.V010_Runtime
 
                binPath, err := example.Build()
index 22ab4d7..057567f 100644 (file)
@@ -15,9 +15,8 @@
 package libcni_test
 
 import (
-       "fmt"
+       "encoding/json"
        "path/filepath"
-       "strings"
 
        . "github.com/onsi/ginkgo"
        . "github.com/onsi/gomega"
@@ -31,7 +30,7 @@ func TestLibcni(t *testing.T) {
        RunSpecs(t, "Libcni Suite")
 }
 
-var plugins = map[string]string{
+var pluginPackages = map[string]string{
        "noop": "github.com/containernetworking/cni/plugins/test/noop",
 }
 
@@ -39,24 +38,21 @@ var pluginPaths map[string]string
 var pluginDirs []string // array of plugin dirs
 
 var _ = SynchronizedBeforeSuite(func() []byte {
-       dirs := make([]string, 0, len(plugins))
 
-       for name, packagePath := range plugins {
+       paths := map[string]string{}
+       for name, packagePath := range pluginPackages {
                execPath, err := gexec.Build(packagePath)
                Expect(err).NotTo(HaveOccurred())
-               dirs = append(dirs, fmt.Sprintf("%s=%s", name, execPath))
+               paths[name] = execPath
        }
+       crossNodeData, err := json.Marshal(paths)
+       Expect(err).NotTo(HaveOccurred())
 
-       return []byte(strings.Join(dirs, ":"))
+       return crossNodeData
 }, func(crossNodeData []byte) {
-       pluginPaths = make(map[string]string)
-       for _, str := range strings.Split(string(crossNodeData), ":") {
-               kvs := strings.SplitN(str, "=", 2)
-               if len(kvs) != 2 {
-                       Fail("Invalid inter-node data...")
-               }
-               pluginPaths[kvs[0]] = kvs[1]
-               pluginDirs = append(pluginDirs, filepath.Dir(kvs[1]))
+       Expect(json.Unmarshal(crossNodeData, &pluginPaths)).To(Succeed())
+       for _, pluginPath := range pluginPaths {
+               pluginDirs = append(pluginDirs, filepath.Dir(pluginPath))
        }
 })
 
index 7e58a9b..4792829 100644 (file)
@@ -18,6 +18,7 @@ import (
        "io/ioutil"
        "os"
        "path/filepath"
+       "runtime"
 
        "github.com/containernetworking/cni/pkg/invoke"
        "github.com/containernetworking/cni/pkg/version"
@@ -38,6 +39,9 @@ var _ = Describe("GetVersion, integration tests", func() {
                pluginDir, err := ioutil.TempDir("", "plugins")
                Expect(err).NotTo(HaveOccurred())
                pluginPath = filepath.Join(pluginDir, "test-plugin")
+               if runtime.GOOS == "windows" {
+                       pluginPath += ".exe"
+               }
        })
 
        AfterEach(func() {
index 1bf406b..787d83d 100644 (file)
@@ -20,6 +20,7 @@ import (
        "io/ioutil"
        "net"
        "path/filepath"
+       "runtime"
        "sync"
 
        "github.com/containernetworking/cni/pkg/types"
@@ -61,6 +62,9 @@ func (e Example) Build() (string, error) {
        }
 
        outBinPath := filepath.Join(buildDir, e.Name)
+       if runtime.GOOS == "windows" {
+               outBinPath += ".exe"
+       }
 
        if err := testhelpers.BuildAt([]byte(e.PluginSource), e.CNIRepoGitRef, outBinPath); err != nil {
                return "", err
index 4115105..3490eda 100644 (file)
@@ -17,6 +17,7 @@ package legacy_examples_test
 import (
        "os"
        "path/filepath"
+       "runtime"
 
        "github.com/containernetworking/cni/pkg/version/legacy_examples"
        . "github.com/onsi/ginkgo"
@@ -29,7 +30,11 @@ var _ = Describe("The v0.1.0 Example", func() {
                pluginPath, err := example.Build()
                Expect(err).NotTo(HaveOccurred())
 
-               Expect(filepath.Base(pluginPath)).To(Equal(example.Name))
+               expectedBaseName := example.Name
+               if runtime.GOOS == "windows" {
+                       expectedBaseName += ".exe"
+               }
+               Expect(filepath.Base(pluginPath)).To(Equal(expectedBaseName))
 
                Expect(os.RemoveAll(pluginPath)).To(Succeed())
        })
index 3473cd5..4fe070f 100644 (file)
@@ -18,6 +18,7 @@ import (
        "os"
        "os/exec"
        "path/filepath"
+       "runtime"
 
        "github.com/containernetworking/cni/pkg/version/testhelpers"
        . "github.com/onsi/ginkgo"
@@ -46,6 +47,9 @@ func main() { skel.PluginMain(c, c) }
                outputDir, err = ioutil.TempDir("", "bin")
                Expect(err).NotTo(HaveOccurred())
                outputFilePath = filepath.Join(outputDir, "some-binary")
+               if runtime.GOOS == "windows" {
+                       outputFilePath += ".exe"
+               }
        })
 
        AfterEach(func() {
index bf92dab..4658fc0 100644 (file)
@@ -140,7 +140,7 @@ var _ = Describe("No-op plugin", func() {
                // Remove the DEBUG option from CNI_ARGS and regular args
                newArgs := "FOO=BAR"
                cmd.Env[len(cmd.Env)-1] = "CNI_ARGS=" + newArgs
-               newStdin := fmt.Sprintf(`{"some":"stdin-json", "cniVersion": "0.3.1", "debugFile": "%s"}`, debugFileName)
+               newStdin := fmt.Sprintf(`{"some":"stdin-json", "cniVersion": "0.3.1", "debugFile": %q}`, debugFileName)
                cmd.Stdin = strings.NewReader(newStdin)
                expectedCmdArgs.Args = newArgs
                expectedCmdArgs.StdinData = []byte(newStdin)