Skip to content

Commit

Permalink
tests(reader) fix tests to support multiple args in state flag
Browse files Browse the repository at this point in the history
  • Loading branch information
raittes committed Apr 1, 2020
1 parent ff8941c commit 74eebfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions file/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func Test_ensureJSON(t *testing.T) {
}

func TestReadKongStateFromStdinFailsToParseText(t *testing.T) {
var filename = "-"
var filenames = []string{"-"}
assert := assert.New(t)
assert.Equal("-", filename)
assert.Equal("-", filenames[0])

var content bytes.Buffer
content.Write([]byte("hunter2\n"))
Expand All @@ -66,15 +66,15 @@ func TestReadKongStateFromStdinFailsToParseText(t *testing.T) {

os.Stdin = tmpfile

c, err := GetContentFromFile(filename)
c, err := GetContentFromFiles(filenames)
assert.NotNil(err)
assert.Nil(c)
}

func TestReadKongStateFromStdin(t *testing.T) {
var filename = "-"
var filenames = []string{"-"}
assert := assert.New(t)
assert.Equal("-", filename)
assert.Equal("-", filenames[0])

var content bytes.Buffer
content.Write([]byte("services:\n- host: test.com\n name: test service\n"))
Expand All @@ -98,7 +98,7 @@ func TestReadKongStateFromStdin(t *testing.T) {

os.Stdin = tmpfile

c, err := GetContentFromFile(filename)
c, err := GetContentFromFiles(filenames)
assert.NotNil(c)
assert.Nil(err)

Expand Down
18 changes: 9 additions & 9 deletions file/readfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_getReaders(t *testing.T) {

func Test_getContent(t *testing.T) {
type args struct {
fileOrDir string
filenames []string
}
tests := []struct {
name string
Expand All @@ -136,37 +136,37 @@ func Test_getContent(t *testing.T) {
}{
{
name: "directory does not exist",
args: args{"testdata/does-not-exist"},
args: args{[]string{"testdata/does-not-exist"}},
want: nil,
wantErr: true,
},
{
name: "empty directory",
args: args{"testdata/emptydir"},
args: args{[]string{"testdata/emptydir"}},
want: &Content{},
wantErr: false,
},
{
name: "directory with empty files",
args: args{"testdata/emptyfiles"},
args: args{[]string{"testdata/emptyfiles"}},
want: &Content{},
wantErr: false,
},
{
name: "bad yaml",
args: args{"testdata/badyaml"},
args: args{[]string{"testdata/badyaml"}},
want: nil,
wantErr: true,
},
{
name: "bad JSON",
args: args{"testdata/badjson"},
args: args{[]string{"testdata/badjson"}},
want: nil,
wantErr: true,
},
{
name: "single file",
args: args{"testdata/file.yaml"},
args: args{[]string{"testdata/file.yaml"}},
want: &Content{
Services: []FService{
{
Expand Down Expand Up @@ -196,7 +196,7 @@ func Test_getContent(t *testing.T) {
},
{
name: "valid directory",
args: args{"testdata/valid"},
args: args{[]string{"testdata/valid"}},
want: &Content{
Info: &Info{
SelectorTags: []string{"tag1"},
Expand Down Expand Up @@ -262,7 +262,7 @@ func Test_getContent(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := getContent(tt.args.fileOrDir)
got, err := getContent(tt.args.filenames)
if (err != nil) != tt.wantErr {
t.Errorf("getContent() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit 74eebfe

Please sign in to comment.