2016-10-18 22:53:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package set
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-02-19 22:56:11 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2017-01-19 18:27:59 +00:00
|
|
|
restclient "k8s.io/client-go/rest"
|
2017-01-24 15:00:24 +00:00
|
|
|
"k8s.io/client-go/rest/fake"
|
2016-10-18 22:53:26 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
|
|
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
2017-02-19 22:56:11 +00:00
|
|
|
"k8s.io/kubernetes/pkg/printers"
|
2016-10-18 22:53:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestImageLocal(t *testing.T) {
|
2017-02-19 22:56:11 +00:00
|
|
|
f, tf, codec, ns := cmdtesting.NewAPIFactory()
|
2016-10-18 22:53:26 +00:00
|
|
|
tf.Client = &fake.RESTClient{
|
2017-01-24 15:00:24 +00:00
|
|
|
APIRegistry: api.Registry,
|
2016-10-18 22:53:26 +00:00
|
|
|
NegotiatedSerializer: ns,
|
|
|
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
|
|
|
t.Fatalf("unexpected request: %s %#v\n%#v", req.Method, req.URL, req)
|
|
|
|
return nil, nil
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
tf.Namespace = "test"
|
2017-01-12 18:17:43 +00:00
|
|
|
tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion}}
|
2016-10-18 22:53:26 +00:00
|
|
|
|
|
|
|
buf := bytes.NewBuffer([]byte{})
|
|
|
|
cmd := NewCmdImage(f, buf, buf)
|
|
|
|
cmd.SetOutput(buf)
|
|
|
|
cmd.Flags().Set("output", "name")
|
2017-05-03 14:04:21 +00:00
|
|
|
cmd.Flags().Set("local", "true")
|
2017-02-19 22:56:11 +00:00
|
|
|
mapper, typer := f.Object()
|
|
|
|
tf.Printer = &printers.NamePrinter{Decoders: []runtime.Decoder{codec}, Typer: typer, Mapper: mapper}
|
2016-10-18 22:53:26 +00:00
|
|
|
|
|
|
|
opts := ImageOptions{FilenameOptions: resource.FilenameOptions{
|
|
|
|
Filenames: []string{"../../../../examples/storage/cassandra/cassandra-controller.yaml"}},
|
|
|
|
Out: buf,
|
|
|
|
Local: true}
|
|
|
|
err := opts.Complete(f, cmd, []string{"cassandra=thingy"})
|
|
|
|
if err == nil {
|
|
|
|
err = opts.Validate()
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
err = opts.Run()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
}
|
2017-02-19 22:56:11 +00:00
|
|
|
if !strings.Contains(buf.String(), "replicationcontrollers/cassandra") {
|
2016-10-18 22:53:26 +00:00
|
|
|
t.Errorf("did not set image: %s", buf.String())
|
|
|
|
}
|
|
|
|
}
|