This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for cmd/pmem-ns-init/main.go
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
}) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters