Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Added test for variables table
Browse files Browse the repository at this point in the history
  • Loading branch information
makkes committed Feb 12, 2019
1 parent c5552de commit 2556ca0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion table/table.go
Expand Up @@ -106,7 +106,7 @@ func calcVarColumnWidths(vars []api.Var) map[string]int {
res := make(map[string]int)
res["key"] = 20
res["value"] = 40
res["protected"] = 7
res["protected"] = 9

for _, v := range vars {
w := len(v.Key)
Expand Down
66 changes: 64 additions & 2 deletions table/table_test.go
Expand Up @@ -167,8 +167,70 @@ func TestIssuesTable(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
PrintIssues(tt.writer, tt.issues)
if tt.writer.String() != tt.out {
t.Errorf("'%s'", strings.Split(tt.writer.String(), "\n")[1])
t.Errorf("Unexpected result: (%d) '%s'", len(tt.writer.String()), tt.writer.String())
t.Errorf("Unexpected result: '%s'", tt.writer.String())
}
})
}
}

func TestVarsTable(t *testing.T) {
varsTableTests := []struct {
name string
writer *strings.Builder
vars []api.Var
out string
}{
{
"empty input",
&strings.Builder{},
[]api.Var{},
"KEY VALUE PROTECTED\n",
},
{
"nil input",
&strings.Builder{},
nil,
"KEY VALUE PROTECTED\n",
},
{
"happy path",
&strings.Builder{},
[]api.Var{
{
Key: "key 1",
Value: "value 1",
Protected: false,
},
{
Key: "",
Value: "",
Protected: true,
},
{
Key: "",
Value: "some value",
Protected: false,
},
{
Key: "some key",
Value: "",
Protected: false,
},
},
`KEY VALUE PROTECTED
key 1 value 1 false
true
some value false
some key false
`,
},
}

for _, tt := range varsTableTests {
t.Run(tt.name, func(t *testing.T) {
PrintVars(tt.writer, tt.vars)
if tt.writer.String() != tt.out {
t.Errorf("Unexpected result: '%s'", tt.writer.String())
}
})
}
Expand Down

0 comments on commit 2556ca0

Please sign in to comment.