|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/openshift/origin/pkg/client/testclient" |
| 5 | + templateapi "github.com/openshift/origin/pkg/template/api" |
| 6 | + kapi "k8s.io/kubernetes/pkg/api" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestTransformTemplate(t *testing.T) { |
| 11 | + templatefoobar := &templateapi.Template{ |
| 12 | + ObjectMeta: kapi.ObjectMeta{ |
| 13 | + Name: "foo_bar_template_name", |
| 14 | + Namespace: "foo_bar_namespace", |
| 15 | + }, |
| 16 | + Parameters: []templateapi.Parameter{ |
| 17 | + {Name: "parameter_foo_bar_exist", Value: "value_foo_bar_exist_old"}, |
| 18 | + {Name: "parameter_foo_bar_2", Value: "value_foo_bar_2"}}, |
| 19 | + } |
| 20 | + oldParameterNum := len(templatefoobar.Parameters) |
| 21 | + testParamMap := map[string]string{} |
| 22 | + testParamMap["parameter_foo_bar_exist"] = "value_foo_bar_exist_new" |
| 23 | + |
| 24 | + fakeosClient := &testclient.Fake{} |
| 25 | + |
| 26 | + template, err := TransformTemplate(templatefoobar, fakeosClient, "foo_bar_namespace", testParamMap) |
| 27 | + if err != nil { |
| 28 | + t.Errorf("unexpect err : %v", err) |
| 29 | + } |
| 30 | + if len(template.Parameters) != oldParameterNum { |
| 31 | + t.Errorf("expect parameters num : %d", oldParameterNum) |
| 32 | + } |
| 33 | + if !(template.Parameters[0].Name == "parameter_foo_bar_exist" && |
| 34 | + template.Parameters[0].Value == "value_foo_bar_exist_new") { |
| 35 | + t.Errorf("expect Name : %q Value : %q get Name : %q Value : %q", |
| 36 | + "parameter_foo_bar_exist", "value_foo_bar_exist_new", template.Parameters[0].Name, template.Parameters[0].Value) |
| 37 | + } |
| 38 | + if !(template.Parameters[1].Name == "parameter_foo_bar_2" && |
| 39 | + template.Parameters[1].Value == "value_foo_bar_2") { |
| 40 | + t.Errorf("expect Name : %q Value : %q get Name : %q Value : %q", |
| 41 | + "parameter_foo_bar_2", "value_foo_bar_2", template.Parameters[1].Name, template.Parameters[1].Value) |
| 42 | + } |
| 43 | +} |
0 commit comments