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": {`
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
"github.com/containernetworking/cni/libcni"
})
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()
package libcni_test
import (
- "fmt"
+ "encoding/json"
"path/filepath"
- "strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
RunSpecs(t, "Libcni Suite")
}
-var plugins = map[string]string{
+var pluginPackages = map[string]string{
"noop": "github.com/containernetworking/cni/plugins/test/noop",
}
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))
}
})
"io/ioutil"
"os"
"path/filepath"
+ "runtime"
"github.com/containernetworking/cni/pkg/invoke"
"github.com/containernetworking/cni/pkg/version"
pluginDir, err := ioutil.TempDir("", "plugins")
Expect(err).NotTo(HaveOccurred())
pluginPath = filepath.Join(pluginDir, "test-plugin")
+ if runtime.GOOS == "windows" {
+ pluginPath += ".exe"
+ }
})
AfterEach(func() {
"io/ioutil"
"net"
"path/filepath"
+ "runtime"
"sync"
"github.com/containernetworking/cni/pkg/types"
}
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
import (
"os"
"path/filepath"
+ "runtime"
"github.com/containernetworking/cni/pkg/version/legacy_examples"
. "github.com/onsi/ginkgo"
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())
})
"os"
"os/exec"
"path/filepath"
+ "runtime"
"github.com/containernetworking/cni/pkg/version/testhelpers"
. "github.com/onsi/ginkgo"
outputDir, err = ioutil.TempDir("", "bin")
Expect(err).NotTo(HaveOccurred())
outputFilePath = filepath.Join(outputDir, "some-binary")
+ if runtime.GOOS == "windows" {
+ outputFilePath += ".exe"
+ }
})
AfterEach(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)