11package main
22
33import (
4- "encoding/json"
54 "strings"
65
7- "github.com/alibaba/pouch/apis/types"
86 "github.com/alibaba/pouch/test/command"
97 "github.com/alibaba/pouch/test/environment"
108
@@ -82,24 +80,24 @@ func (suite *PouchRunDNSSuite) TestRunWithDNSFlags(c *check.C) {
8280 defer DelContainerForceMultyTime (c , cname )
8381 res .Assert (c , icmd .Success )
8482
85- // test if the value is in inspect result
86- inspectRes := command .PouchRun ("inspect" , cname )
87- res .Assert (c , icmd .Success )
88-
89- result := []types.ContainerJSON {}
90- if err := json .Unmarshal ([]byte (inspectRes .Stdout ()), & result ); err != nil {
91- c .Errorf ("failed to decode inspect output: %v" , err )
92- }
93-
94- c .Assert (result [0 ].HostConfig .DNS , check .DeepEquals , []string {"1.2.3.4" })
95- c .Assert (result [0 ].HostConfig .DNSOptions , check .DeepEquals , []string {"timeout:3" })
96- c .Assert (result [0 ].HostConfig .DNSSearch , check .DeepEquals , []string {"example.com" })
97-
9883 // test if the value is correct in container
9984 out := strings .Trim (res .Stdout (), "\n " )
10085 c .Assert (strings .Contains (out , "nameserver 1.2.3.4" ), check .Equals , true )
10186 c .Assert (strings .Contains (out , "options timeout:3" ), check .Equals , true )
10287 c .Assert (strings .Contains (out , "search example.com" ), check .Equals , true )
88+
89+ // test if the value is in inspect result
90+ dns , err := inspectFilter (cname , ".HostConfig.DNS" )
91+ c .Assert (err , check .IsNil )
92+ c .Assert (dns , check .Equals , "[1.2.3.4]" )
93+
94+ dnsOptions , err := inspectFilter (cname , ".HostConfig.DNSOptions" )
95+ c .Assert (err , check .IsNil )
96+ c .Assert (dnsOptions , check .Equals , "[timeout:3]" )
97+
98+ dnsSearch , err := inspectFilter (cname , ".HostConfig.DNSSearch" )
99+ c .Assert (err , check .IsNil )
100+ c .Assert (dnsSearch , check .Equals , "[example.com]" )
103101}
104102
105103// TestRunWithDNSRepeatFlags tests repeated DNS related flags.
@@ -118,22 +116,22 @@ func (suite *PouchRunDNSSuite) TestRunWithDNSRepeatFlags(c *check.C) {
118116 defer DelContainerForceMultyTime (c , cname )
119117 res .Assert (c , icmd .Success )
120118
121- // test if the value is in inspect result
122- inspectRes := command .PouchRun ("inspect" , cname )
123- res .Assert (c , icmd .Success )
124-
125- result := []types.ContainerJSON {}
126- if err := json .Unmarshal ([]byte (inspectRes .Stdout ()), & result ); err != nil {
127- c .Errorf ("failed to decode inspect output: %v" , err )
128- }
129-
130- c .Assert (result [0 ].HostConfig .DNS , check .DeepEquals , []string {"1.2.3.4" , "2.3.4.5" })
131- c .Assert (result [0 ].HostConfig .DNSOptions , check .DeepEquals , []string {"timeout:3" , "ndots:9" })
132- c .Assert (result [0 ].HostConfig .DNSSearch , check .DeepEquals , []string {"mydomain" , "mydomain2" })
133-
134119 // test if the value is correct in container
135120 out := strings .Trim (res .Stdout (), "\n " )
136121 c .Assert (strings .Contains (out , "nameserver 1.2.3.4\n nameserver 2.3.4.5" ), check .Equals , true )
137122 c .Assert (strings .Contains (out , "options timeout:3 ndots:9" ), check .Equals , true )
138123 c .Assert (strings .Contains (out , "search mydomain mydomain2" ), check .Equals , true )
124+
125+ // test if the value is in inspect result
126+ dns , err := inspectFilter (cname , ".HostConfig.DNS" )
127+ c .Assert (err , check .IsNil )
128+ c .Assert (dns , check .Equals , "[1.2.3.4 2.3.4.5]" )
129+
130+ dnsOptions , err := inspectFilter (cname , ".HostConfig.DNSOptions" )
131+ c .Assert (err , check .IsNil )
132+ c .Assert (dnsOptions , check .Equals , "[timeout:3 ndots:9" )
133+
134+ dnsSearch , err := inspectFilter (cname , ".HostConfig.DNSSearch" )
135+ c .Assert (err , check .IsNil )
136+ c .Assert (dnsSearch , check .Equals , "[mydomain mydomain2]" )
139137}
0 commit comments