@@ -78,6 +78,43 @@ func TestSetEnvLocal(t *testing.T) {
78
78
}
79
79
}
80
80
81
+ func TestSetEnvLocalNamespace (t * testing.T ) {
82
+ tf := cmdtesting .NewTestFactory ().WithNamespace ("test" )
83
+ defer tf .Cleanup ()
84
+
85
+ tf .Client = & fake.RESTClient {
86
+ GroupVersion : schema.GroupVersion {Version : "" },
87
+ NegotiatedSerializer : scheme .Codecs .WithoutConversion (),
88
+ Client : fake .CreateHTTPClient (func (req * http.Request ) (* http.Response , error ) {
89
+ t .Fatalf ("unexpected request: %s %#v\n %#v" , req .Method , req .URL , req )
90
+ return nil , nil
91
+ }),
92
+ }
93
+ tf .ClientConfigVal = & restclient.Config {ContentConfig : restclient.ContentConfig {GroupVersion : & schema.GroupVersion {Version : "" }}}
94
+ outputFormat := "yaml"
95
+
96
+ streams , _ , buf , bufErr := genericclioptions .NewTestIOStreams ()
97
+ opts := NewEnvOptions (streams )
98
+ opts .PrintFlags = genericclioptions .NewPrintFlags ("" ).WithDefaultOutput (outputFormat ).WithTypeSetter (scheme .Scheme )
99
+ opts .FilenameOptions = resource.FilenameOptions {
100
+ Filenames : []string {"../../../../test/fixtures/pkg/kubectl/cmd/set/namespaced-resource.yaml" },
101
+ }
102
+ opts .Local = true
103
+
104
+ err := opts .Complete (tf , NewCmdEnv (tf , streams ), []string {"env=prod" })
105
+ assert .NoError (t , err )
106
+ err = opts .Validate ()
107
+ assert .NoError (t , err )
108
+ err = opts .RunEnv ()
109
+ assert .NoError (t , err )
110
+ if bufErr .Len () > 0 {
111
+ t .Errorf ("unexpected error: %s" , string (bufErr .String ()))
112
+ }
113
+ if ! strings .Contains (buf .String (), "namespace: existing-ns" ) {
114
+ t .Errorf ("did not set env: %s" , buf .String ())
115
+ }
116
+ }
117
+
81
118
func TestSetMultiResourcesEnvLocal (t * testing.T ) {
82
119
tf := cmdtesting .NewTestFactory ().WithNamespace ("test" )
83
120
defer tf .Cleanup ()
0 commit comments