-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(GODT-1605): add test coverage for nil hierarchy delimiter.
- Loading branch information
Showing
6 changed files
with
113 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,71 @@ | ||
package state | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestListSuperiorNames(t *testing.T) { | ||
tests := []struct { | ||
for name, data := range map[string]struct { | ||
name, delimiter string | ||
|
||
want []string | ||
want []string | ||
}{ | ||
{ | ||
"no parents": { | ||
name: "this", | ||
delimiter: "/", | ||
want: []string{}, | ||
want: nil, | ||
}, | ||
{ | ||
"has parents": { | ||
name: "this/is/a/test", | ||
delimiter: "/", | ||
want: []string{"this", "this/is", "this/is/a"}, | ||
}, | ||
{ | ||
name: "/this/is/a/test", | ||
"wrong delimiter": { | ||
name: "this.is.a.test", | ||
delimiter: "/", | ||
want: []string{"/this", "/this/is", "/this/is/a"}, | ||
want: nil, | ||
}, | ||
"nil delimiter": { | ||
name: "/nil/delimiter.used", | ||
delimiter: "", | ||
want: nil, | ||
}, | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
require.Equal(t, data.want, listSuperiors(data.name, data.delimiter)) | ||
}) | ||
} | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
|
||
t.Run(fmt.Sprintf("%#v", tt), func(t *testing.T) { | ||
if res := listSuperiors(tt.name, tt.delimiter); strings.Join(res, "") != strings.Join(tt.want, "") { | ||
t.Errorf("expected result of %v but got %v", tt.want, res) | ||
} | ||
func TestListInferiorNames(t *testing.T) { | ||
for name, data := range map[string]struct { | ||
parent string | ||
delimiter string | ||
names []string | ||
want []string | ||
}{ | ||
"no children": { | ||
parent: "this", | ||
delimiter: "/", | ||
names: []string{"one", "two", "three", "this", "a/b", "c/d"}, | ||
want: []string{}, | ||
}, | ||
"has children": { | ||
parent: "this", | ||
delimiter: "/", | ||
names: []string{"a/b", "this/one", "this", "this/two", "this/one/two/three", "c/d"}, | ||
want: []string{"this/two", "this/one/two/three", "this/one"}, | ||
}, | ||
"nil delimiter": { | ||
parent: "this", | ||
delimiter: "", | ||
names: []string{"a/b", "this/one", "this", "this/two", "this/one/two/three", "c/d"}, | ||
want: []string{}, | ||
}, | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
require.Equal(t, data.want, listInferiors(data.parent, data.delimiter, data.names)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters