@@ -20,6 +20,7 @@ import (
20
20
"bytes"
21
21
"io/ioutil"
22
22
"net/http"
23
+ "strings"
23
24
"testing"
24
25
25
26
"github.com/stretchr/testify/assert"
@@ -52,7 +53,7 @@ func TestCreateDeployment(t *testing.T) {
52
53
53
54
ioStreams , _ , buf , _ := genericclioptions .NewTestIOStreams ()
54
55
cmd := NewCmdCreateDeployment (tf , ioStreams )
55
- cmd .Flags ().Set ("dry-run" , "true " )
56
+ cmd .Flags ().Set ("dry-run" , "client " )
56
57
cmd .Flags ().Set ("output" , "name" )
57
58
cmd .Flags ().Set ("image" , "hollywood/jonny.depp:v2" )
58
59
cmd .Run (cmd , []string {depName })
@@ -62,6 +63,37 @@ func TestCreateDeployment(t *testing.T) {
62
63
}
63
64
}
64
65
66
+ func TestCreateDeploymentWithPort (t * testing.T ) {
67
+ depName := "jonny-dep"
68
+ port := "5701"
69
+ tf := cmdtesting .NewTestFactory ().WithNamespace ("test" )
70
+ defer tf .Cleanup ()
71
+
72
+ ns := scheme .Codecs .WithoutConversion ()
73
+ fakeDiscovery := "{\" kind\" :\" APIResourceList\" ,\" apiVersion\" :\" v1\" ,\" groupVersion\" :\" apps/v1\" ,\" resources\" :[{\" name\" :\" deployments\" ,\" singularName\" :\" \" ,\" namespaced\" :true,\" kind\" :\" Deployment\" ,\" verbs\" :[\" create\" ,\" delete\" ,\" deletecollection\" ,\" get\" ,\" list\" ,\" patch\" ,\" update\" ,\" watch\" ],\" shortNames\" :[\" deploy\" ],\" categories\" :[\" all\" ]}]}"
74
+ tf .Client = & fake.RESTClient {
75
+ NegotiatedSerializer : ns ,
76
+ Client : fake .CreateHTTPClient (func (req * http.Request ) (* http.Response , error ) {
77
+ return & http.Response {
78
+ StatusCode : http .StatusOK ,
79
+ Body : ioutil .NopCloser (bytes .NewBuffer ([]byte (fakeDiscovery ))),
80
+ }, nil
81
+ }),
82
+ }
83
+ tf .ClientConfigVal = & restclient.Config {}
84
+
85
+ ioStreams , _ , buf , _ := genericclioptions .NewTestIOStreams ()
86
+ cmd := NewCmdCreateDeployment (tf , ioStreams )
87
+ cmd .Flags ().Set ("dry-run" , "client" )
88
+ cmd .Flags ().Set ("output" , "yaml" )
89
+ cmd .Flags ().Set ("port" , port )
90
+ cmd .Flags ().Set ("image" , "hollywood/jonny.depp:v2" )
91
+ cmd .Run (cmd , []string {depName })
92
+ if ! strings .Contains (buf .String (), port ) {
93
+ t .Errorf ("unexpected output: %s\n expected to contain: %s" , buf .String (), port )
94
+ }
95
+ }
96
+
65
97
func TestCreateDeploymentNoImage (t * testing.T ) {
66
98
depName := "jonny-dep"
67
99
tf := cmdtesting .NewTestFactory ().WithNamespace ("test" )
0 commit comments