aboutsummaryrefslogtreecommitdiffstats
path: root/internal/pkg/testing
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2018-11-10 09:56:52 -0800
committerVictor Morales <victor.morales@intel.com>2018-11-20 01:50:58 -0800
commit5026d1d89b05eac5e004279b742df6745a73d93a (patch)
tree8f9aed1e476706e008b746debda6d616bd0ac7a5 /internal/pkg/testing
parent9506ae48eb545d502cc3685a99862740d28e7afb (diff)
Seed code for the Plugin
The code includes ovn4nfvk8s Plugin & CNI. It implements multiple OVN interfaces for Pods and assumes Multus (or similar CNI) calls its CNI not as first CNI. Change-Id: I524c1d18752eb6dbc8d34addd3b60d5bbaa06ff4 Signed-off-by: Ritu Sood <ritu.sood@intel.com> Signed-off-by: Victor Morales <victor.morales@intel.com>
Diffstat (limited to 'internal/pkg/testing')
-rw-r--r--internal/pkg/testing/testing.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/pkg/testing/testing.go b/internal/pkg/testing/testing.go
new file mode 100644
index 0000000..4c2afad
--- /dev/null
+++ b/internal/pkg/testing/testing.go
@@ -0,0 +1,55 @@
+package testing
+
+import (
+ "strings"
+
+ kexec "k8s.io/utils/exec"
+ fakeexec "k8s.io/utils/exec/testing"
+
+ "github.com/onsi/gomega"
+)
+
+// ExpectedCmd contains properties that the testcase expects a called command
+// to have as well as the output that the fake command should return
+type ExpectedCmd struct {
+ // Cmd should be the command-line string of the executable name and all arguments it is expected to be called with
+ Cmd string
+ // Output is any stdout output which Cmd should produce
+ Output string
+ // Stderr is any stderr output which Cmd should produce
+ Stderr string
+ // Err is any error that should be returned for the invocation of Cmd
+ Err error
+}
+
+// AddFakeCmd takes the ExpectedCmd and appends its runner function to
+// a fake command action list
+func AddFakeCmd(fakeCmds []fakeexec.FakeCommandAction, expected *ExpectedCmd) []fakeexec.FakeCommandAction {
+ return append(fakeCmds, func(cmd string, args ...string) kexec.Cmd {
+ parts := strings.Split(expected.Cmd, " ")
+ gomega.Expect(cmd).To(gomega.Equal("/fake-bin/" + parts[0]))
+ gomega.Expect(strings.Join(args, " ")).To(gomega.Equal(strings.Join(parts[1:], " ")))
+ return &fakeexec.FakeCmd{
+ Argv: parts[1:],
+ CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
+ func() ([]byte, error) {
+ return []byte(expected.Output), expected.Err
+ },
+ },
+ RunScript: []fakeexec.FakeRunAction{
+ func() ([]byte, []byte, error) {
+ return []byte(expected.Output), []byte(expected.Stderr), expected.Err
+ },
+ },
+ }
+ })
+}
+
+// AddFakeCmdsNoOutputNoError takes a list of commands and appends those commands
+// to the expected command set. The command cannot return any output or error.
+func AddFakeCmdsNoOutputNoError(fakeCmds []fakeexec.FakeCommandAction, commands []string) []fakeexec.FakeCommandAction {
+ for _, cmd := range commands {
+ fakeCmds = AddFakeCmd(fakeCmds, &ExpectedCmd{Cmd: cmd})
+ }
+ return fakeCmds
+}