Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libcni/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"os"
"path/filepath"
"sort"

"github.com/containernetworking/cni/pkg/types"
)

type NotFoundError struct {
Expand All @@ -41,8 +43,8 @@ func (e NoConfigsFoundError) Error() string {
}

func ConfFromBytes(bytes []byte) (*NetworkConfig, error) {
conf := &NetworkConfig{Bytes: bytes}
if err := json.Unmarshal(bytes, &conf.Network); err != nil {
conf := &NetworkConfig{Bytes: bytes, Network: &types.NetConf{}}
if err := json.Unmarshal(bytes, conf.Network); err != nil {
return nil, fmt.Errorf("error parsing configuration: %w", err)
}
if conf.Network.Type == "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/040/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ var _ = Describe("040 types operations", func() {
}`))

recovered := &types040.IPConfig{}
Expect(json.Unmarshal(jsonBytes, &recovered)).To(Succeed())
Expect(json.Unmarshal(jsonBytes, recovered)).To(Succeed())
Expect(recovered).To(Equal(ipc))
})

Expand All @@ -363,7 +363,7 @@ var _ = Describe("040 types operations", func() {
Context("when unmarshalling json fails", func() {
It("returns an error", func() {
recovered := &types040.IPConfig{}
err := json.Unmarshal([]byte(`{"address": 5}`), &recovered)
err := json.Unmarshal([]byte(`{"address": 5}`), recovered)
Expect(err).To(MatchError(HavePrefix("json: cannot unmarshal")))
})
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/100/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,14 @@ var _ = Describe("Current types operations", func() {
}`))

recovered := &current.IPConfig{}
Expect(json.Unmarshal(jsonBytes, &recovered)).To(Succeed())
Expect(json.Unmarshal(jsonBytes, recovered)).To(Succeed())
Expect(recovered).To(Equal(ipc))
})

Context("when unmarshalling json fails", func() {
It("returns an error", func() {
recovered := &current.IPConfig{}
err := json.Unmarshal([]byte(`{"address": 5}`), &recovered)
err := json.Unmarshal([]byte(`{"address": 5}`), recovered)
Expect(err).To(MatchError(HavePrefix("json: cannot unmarshal")))
})
})
Expand Down