Skip to content

Commit

Permalink
tests: small cleanup and removal of one useless testcase
Browse files Browse the repository at this point in the history
The testcase checking if a prevResult was invalid is not actually
useful, because it was testing that an empty prevResult could be
unmarshalled. But due to an oversight, prevResults may not have
a CNIVersion key, which is all we can check for validity.

Signed-off-by: Dan Williams <dcbw@redhat.com>
  • Loading branch information
dcbw committed Oct 28, 2020
1 parent 32d9656 commit dbe3a52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
18 changes: 8 additions & 10 deletions libcni/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ var _ = Describe("Invoking plugins", func() {

Context("equal to 0.4.0", func() {
It("passes a prevResult to the plugin", func() {
ipResult := `{
"cniVersion": "0.4.0",
"ips": [{"version": "4", "address": "10.1.2.3/24"}],
"dns": {}
}`

var err error
netConfig, err = libcni.ConfFromBytes([]byte(`{
"type": "noop",
Expand All @@ -572,18 +578,10 @@ var _ = Describe("Invoking plugins", func() {
}`))
Expect(err).NotTo(HaveOccurred())

err = ioutil.WriteFile(cacheFile, []byte(`{
"cniVersion": "0.4.0",
"ips": [{"version": "4", "address": "10.1.2.3/24"}],
"dns": {}
}`), 0600)
err = ioutil.WriteFile(cacheFile, []byte(ipResult), 0600)
Expect(err).NotTo(HaveOccurred())

debug.ReportResult = `{
"cniVersion": "0.4.0",
"ips": [{"version": "4", "address": "10.1.2.3/24"}],
"dns": {}
}`
debug.ReportResult = ipResult
Expect(debug.WriteDebug(debugFilePath)).To(Succeed())

err = cniConfig.CheckNetwork(ctx, netConfig, runtimeConfig)
Expand Down
14 changes: 0 additions & 14 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,6 @@ var _ = Describe("Version operations", func() {
Expect(err).To(MatchError("could not parse prevResult: result type supports [1.0.0] but unmarshalled CNIVersion is \"5678.456\""))
})

It("fails if the prevResult is invalid", func() {
conf := &types.NetConf{
CNIVersion: current.ImplementedSpecVersion,
Name: "foobar",
Type: "baz",
RawPrevResult: map[string]interface{}{
"adsfasdfasdfasdfasdfaf": nil,
},
}

err := version.ParsePrevResult(conf)
Expect(err).To(MatchError("could not parse prevResult: result type supports [1.0.0] but unmarshalled CNIVersion is \"\""))
})

It("fails if the prevResult version does not match the prevResult version", func() {
conf := &types.NetConf{
CNIVersion: current.ImplementedSpecVersion,
Expand Down

0 comments on commit dbe3a52

Please sign in to comment.