Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Added unit tests for cmd/pmem-ns-init/main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
okartau committed Apr 24, 2019
1 parent 984536f commit af2596b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
78 changes: 78 additions & 0 deletions cmd/pmem-ns-init/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main_test

import (
"flag"
"testing"

pmemnsinit "github.com/intel/pmem-csi/cmd/pmem-ns-init"
"k8s.io/klog"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func init() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()
}

func TestPmemNSInit(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "NSInit Suite")
}

var _ = BeforeSuite(func() {
var err error
Expect(err).NotTo(HaveOccurred())
})

var _ = AfterSuite(func() {
})

var _ = Describe("pmem-ns-init", func() {
//BeforeEach(func() {
//})

//AfterEach(func() {
//})

Context("Check arguments", func() {

type cases struct {
name string
namespacesize, useforfsdax, useforsector int
}
goodcases := []cases{
{"namespacesize ok", 32, 0, 0},
{"useforfsdax ok", 32, 50, 0},
{"useforsector ok", 32, 0, 50},
{"useforfsdax and useforsector combined 100", 32, 70, 30},
{"useforfsdax and useforsector combined less than 100", 32, 40, 30},
}
badcases := []cases{
{"namespacesize negative", -1, 0, 0},
{"namespacesize too small", 1, 0, 0},
{"useforfsdax negative", 32, -1, 0},
{"useforsector negative", 32, 0, -1},
{"useforfsdax too large", 32, 101, 0},
{"useforsector too large", 32, 0, 101},
{"useforfsdax and useforsector combined too large", 32, 51, 51},
}

for _, c := range goodcases {
c := c
It(c.name, func() {
err := pmemnsinit.CheckArgs(c.namespacesize, c.useforfsdax, c.useforsector)
Expect(err).NotTo(HaveOccurred())
})
}
for _, c := range badcases {
c := c
It(c.name, func() {
err := pmemnsinit.CheckArgs(c.namespacesize, c.useforfsdax, c.useforsector)
Expect(err).To(HaveOccurred())
})
}
})
})
2 changes: 1 addition & 1 deletion test/test.make
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEST_CMD=go test
TEST_ARGS=$(IMPORT_PATH)/pkg/...
TEST_ARGS=$(IMPORT_PATH)/cmd/... $(IMPORT_PATH)/pkg/...

.PHONY: vet
test: vet
Expand Down

0 comments on commit af2596b

Please sign in to comment.