@@ -52,6 +52,59 @@ func TestJSONPrinter(t *testing.T) {
52
52
testPrinter (t , & JSONPrinter {}, json .Unmarshal )
53
53
}
54
54
55
+ func TestPrintJSON (t * testing.T ) {
56
+ buf := bytes .NewBuffer ([]byte {})
57
+ if err := Print (buf , & api.Pod {ObjectMeta : api.ObjectMeta {Name : "foo" }}, "json" , "" , nil ); err != nil {
58
+ t .Errorf ("unexpected error: %#v" , err )
59
+ }
60
+ obj := map [string ]interface {}{}
61
+ if err := json .Unmarshal (buf .Bytes (), & obj ); err != nil {
62
+ t .Errorf ("unexpected error: %#v\n %s" , err , buf .String ())
63
+ }
64
+ }
65
+
66
+ func TestPrintYAML (t * testing.T ) {
67
+ buf := bytes .NewBuffer ([]byte {})
68
+ if err := Print (buf , & api.Pod {ObjectMeta : api.ObjectMeta {Name : "foo" }}, "yaml" , "" , nil ); err != nil {
69
+ t .Errorf ("unexpected error: %#v" , err )
70
+ }
71
+ obj := map [string ]interface {}{}
72
+ if err := yaml .Unmarshal (buf .Bytes (), & obj ); err != nil {
73
+ t .Errorf ("unexpected error: %#v\n %s" , err , buf .String ())
74
+ }
75
+ }
76
+
77
+ func TestPrintTemplate (t * testing.T ) {
78
+ buf := bytes .NewBuffer ([]byte {})
79
+ if err := Print (buf , & api.Pod {ObjectMeta : api.ObjectMeta {Name : "foo" }}, "template" , "{{ .Name }}" , nil ); err != nil {
80
+ t .Errorf ("unexpected error: %#v" , err )
81
+ }
82
+ if buf .String () != "foo" {
83
+ t .Errorf ("unexpected output: %s" , buf .String ())
84
+ }
85
+ }
86
+
87
+ func TestPrintEmptyTemplate (t * testing.T ) {
88
+ buf := bytes .NewBuffer ([]byte {})
89
+ if err := Print (buf , & api.Pod {ObjectMeta : api.ObjectMeta {Name : "foo" }}, "template" , "" , nil ); err == nil {
90
+ t .Errorf ("unexpected non-error" )
91
+ }
92
+ }
93
+
94
+ func TestPrintBadTemplate (t * testing.T ) {
95
+ buf := bytes .NewBuffer ([]byte {})
96
+ if err := Print (buf , & api.Pod {ObjectMeta : api.ObjectMeta {Name : "foo" }}, "template" , "{{ .Name" , nil ); err == nil {
97
+ t .Errorf ("unexpected non-error" )
98
+ }
99
+ }
100
+
101
+ func TestPrintBadTemplateFile (t * testing.T ) {
102
+ buf := bytes .NewBuffer ([]byte {})
103
+ if err := Print (buf , & api.Pod {ObjectMeta : api.ObjectMeta {Name : "foo" }}, "templatefile" , "" , nil ); err == nil {
104
+ t .Errorf ("unexpected non-error" )
105
+ }
106
+ }
107
+
55
108
func testPrinter (t * testing.T , printer ResourcePrinter , unmarshalFunc func (data []byte , v interface {}) error ) {
56
109
buf := bytes .NewBuffer ([]byte {})
57
110
0 commit comments