Merge pull request #161 from steveeJ/skel-tests
pkg/skel: add rudimentary unit tests
This commit is contained in:
commit
6ef5ef1ec1
13
pkg/skel/skel_suite_test.go
Normal file
13
pkg/skel/skel_suite_test.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package skel
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSkel(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "Skel Suite")
|
||||||
|
}
|
61
pkg/skel/skel_test.go
Normal file
61
pkg/skel/skel_test.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package skel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Skel", func() {
|
||||||
|
var (
|
||||||
|
fNoop = func(_ *CmdArgs) error { return nil }
|
||||||
|
// fErr = func(_ *CmdArgs) error { return errors.New("dummy") }
|
||||||
|
envVars = []struct {
|
||||||
|
name string
|
||||||
|
val string
|
||||||
|
}{
|
||||||
|
{"CNI_CONTAINERID", "dummy"},
|
||||||
|
{"CNI_NETNS", "dummy"},
|
||||||
|
{"CNI_IFNAME", "dummy"},
|
||||||
|
{"CNI_ARGS", "dummy"},
|
||||||
|
{"CNI_PATH", "dummy"},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
It("Must be possible to set the env vars", func() {
|
||||||
|
for _, v := range envVars {
|
||||||
|
err := os.Setenv(v.name, v.val)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("When dummy environment variables are passed", func() {
|
||||||
|
|
||||||
|
It("should not fail with ADD and noop callback", func() {
|
||||||
|
err := os.Setenv("CNI_COMMAND", "ADD")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
PluginMain(fNoop, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: figure out howto mock printing and os.Exit()
|
||||||
|
// It("should fail with ADD and error callback", func() {
|
||||||
|
// err := os.Setenv("CNI_COMMAND", "ADD")
|
||||||
|
// Expect(err).NotTo(HaveOccurred())
|
||||||
|
// PluginMain(fErr, nil)
|
||||||
|
// })
|
||||||
|
|
||||||
|
It("should not fail with DEL and noop callback", func() {
|
||||||
|
err := os.Setenv("CNI_COMMAND", "DEL")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
PluginMain(nil, fNoop)
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: figure out howto mock printing and os.Exit()
|
||||||
|
// It("should fail with DEL and error callback", func() {
|
||||||
|
// err := os.Setenv("CNI_COMMAND", "DEL")
|
||||||
|
// Expect(err).NotTo(HaveOccurred())
|
||||||
|
// PluginMain(fErr, nil)
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
})
|
4
test
4
test
@ -11,8 +11,8 @@ set -e
|
|||||||
|
|
||||||
source ./build
|
source ./build
|
||||||
|
|
||||||
TESTABLE="plugins/ipam/dhcp plugins/main/loopback pkg/invoke pkg/ns"
|
TESTABLE="plugins/ipam/dhcp plugins/main/loopback pkg/invoke pkg/ns pkg/skel"
|
||||||
FORMATTABLE="$TESTABLE libcni pkg/ip pkg/ns pkg/types pkg/ipam pkg/skel plugins/ipam/host-local plugins/main/bridge plugins/meta/flannel plugins/meta/tuning"
|
FORMATTABLE="$TESTABLE libcni pkg/ip pkg/ns pkg/types pkg/ipam plugins/ipam/host-local plugins/main/bridge plugins/meta/flannel plugins/meta/tuning"
|
||||||
|
|
||||||
# user has not provided PKG override
|
# user has not provided PKG override
|
||||||
if [ -z "$PKG" ]; then
|
if [ -z "$PKG" ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user