mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
Address comments.
This commit is contained in:
68
pkg/kubectl/cmd/clusterinfo_dump_test.go
Normal file
68
pkg/kubectl/cmd/clusterinfo_dump_test.go
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetWriterNoOp(t *testing.T) {
|
||||
tests := []string{"", "-"}
|
||||
for _, test := range tests {
|
||||
out := &bytes.Buffer{}
|
||||
f, _, _ := NewAPIFactory()
|
||||
cmd := NewCmdClusterInfoDump(f, os.Stdout)
|
||||
cmd.Flag("output-directory").Value.Set(test)
|
||||
writer := getWriter(cmd, out, "/some/file/that/should/be/ignored")
|
||||
if writer != out {
|
||||
t.Errorf("expected: %v, saw: %v", out, writer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWriterFile(t *testing.T) {
|
||||
file := "output.json"
|
||||
dir, err := ioutil.TempDir(os.TempDir(), "out")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
fullPath := path.Join(dir, file)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
out := &bytes.Buffer{}
|
||||
f, _, _ := NewAPIFactory()
|
||||
cmd := NewCmdClusterInfoDump(f, os.Stdout)
|
||||
cmd.Flag("output-directory").Value.Set(dir)
|
||||
writer := getWriter(cmd, out, file)
|
||||
if writer == out {
|
||||
t.Errorf("expected: %v, saw: %v", out, writer)
|
||||
}
|
||||
output := "some data here"
|
||||
writer.Write([]byte(output))
|
||||
|
||||
data, err := ioutil.ReadFile(fullPath)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if string(data) != output {
|
||||
t.Errorf("expected: %v, saw: %v", output, data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user