Fix testings accross the project

Signed-off-by: Pengfei Ni <feiskyer@gmail.com>
This commit is contained in:
Pengfei Ni
2017-05-03 23:21:44 +08:00
parent 27a5b994c2
commit f197c01b62
4 changed files with 11 additions and 8 deletions

View File

@ -297,6 +297,7 @@ var _ = Describe("Invoking plugins", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(&current.Result{ Expect(result).To(Equal(&current.Result{
CNIVersion: current.ImplementedSpecVersion,
IPs: []*current.IPConfig{ IPs: []*current.IPConfig{
{ {
Version: "4", Version: "4",
@ -479,6 +480,7 @@ var _ = Describe("Invoking plugins", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(&current.Result{ Expect(result).To(Equal(&current.Result{
CNIVersion: current.ImplementedSpecVersion,
// IP4 added by first plugin // IP4 added by first plugin
IPs: []*current.IPConfig{ IPs: []*current.IPConfig{
{ {

View File

@ -24,9 +24,9 @@ import (
"github.com/containernetworking/cni/pkg/types/020" "github.com/containernetworking/cni/pkg/types/020"
) )
const implementedSpecVersion string = "0.3.1" const ImplementedSpecVersion string = "0.3.1"
var SupportedVersions = []string{"0.3.0", implementedSpecVersion} var SupportedVersions = []string{"0.3.0", ImplementedSpecVersion}
func NewResult(data []byte) (types.Result, error) { func NewResult(data []byte) (types.Result, error) {
result := &Result{} result := &Result{}
@ -37,7 +37,7 @@ func NewResult(data []byte) (types.Result, error) {
} }
func GetResult(r types.Result) (*Result, error) { func GetResult(r types.Result) (*Result, error) {
resultCurrent, err := r.GetAsVersion(implementedSpecVersion) resultCurrent, err := r.GetAsVersion(ImplementedSpecVersion)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -63,7 +63,7 @@ func convertFrom020(result types.Result) (*Result, error) {
} }
newResult := &Result{ newResult := &Result{
CNIVersion: implementedSpecVersion, CNIVersion: ImplementedSpecVersion,
DNS: oldResult.DNS, DNS: oldResult.DNS,
Routes: []*types.Route{}, Routes: []*types.Route{},
} }
@ -118,7 +118,7 @@ func convertFrom030(result types.Result) (*Result, error) {
if !ok { if !ok {
return nil, fmt.Errorf("failed to convert result") return nil, fmt.Errorf("failed to convert result")
} }
newResult.CNIVersion = implementedSpecVersion newResult.CNIVersion = ImplementedSpecVersion
return newResult, nil return newResult, nil
} }
@ -193,12 +193,12 @@ func (r *Result) convertTo020() (*types020.Result, error) {
} }
func (r *Result) Version() string { func (r *Result) Version() string {
return implementedSpecVersion return ImplementedSpecVersion
} }
func (r *Result) GetAsVersion(version string) (types.Result, error) { func (r *Result) GetAsVersion(version string) (types.Result, error) {
switch version { switch version {
case "0.3.0", implementedSpecVersion: case "0.3.0", ImplementedSpecVersion:
r.CNIVersion = version r.CNIVersion = version
return r, nil return r, nil
case types020.SupportedVersions[0], types020.SupportedVersions[1], types020.SupportedVersions[2]: case types020.SupportedVersions[0], types020.SupportedVersions[1], types020.SupportedVersions[2]:

View File

@ -174,7 +174,7 @@ var _ = Describe("Current types operations", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(string(out)).To(Equal(`{ Expect(string(out)).To(Equal(`{
"cniVersion": "0.1.0", "cniVersion": "0.2.0",
"ip4": { "ip4": {
"ip": "1.2.3.30/24", "ip": "1.2.3.30/24",
"gateway": "1.2.3.1", "gateway": "1.2.3.1",

View File

@ -130,6 +130,7 @@ var _ = Describe("No-op plugin", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0)) Eventually(session).Should(gexec.Exit(0))
Expect(session.Out.Contents()).To(MatchJSON(`{ Expect(session.Out.Contents()).To(MatchJSON(`{
"cniVersion": "0.3.1",
"ips": [{"version": "4", "address": "10.1.2.3/24"}], "ips": [{"version": "4", "address": "10.1.2.3/24"}],
"dns": {"nameservers": ["1.2.3.4"]} "dns": {"nameservers": ["1.2.3.4"]}
}`)) }`))