Skip to content

Commit 3499b65

Browse files
committed
Update specs_test.go
When checking storage options output printed, ignore the order because Golang map iteration is randomized
1 parent 01cac70 commit 3499b65

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

cli/feast/pkg/printer/specs_test.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package printer
22

33
import (
44
"fmt"
5+
"strings"
56
"testing"
67

78
"github.com/gojek/feast/cli/feast/pkg/timeutil"
@@ -132,22 +133,51 @@ func TestPrintStorage(t *testing.T) {
132133
Spec: &specs.StorageSpec{
133134
Id: "REDIS1",
134135
Type: "redis",
135-
Options: map[string]string{
136-
"option1": "value1",
137-
"option2": "value2",
138-
},
139136
},
140137
LastUpdated: &timestamp.Timestamp{Seconds: 1},
141138
}
142139
out := PrintStorageDetail(storageDetail)
143140
expected := fmt.Sprintf(`Id: REDIS1
144141
Type: redis
145142
Options:
146-
option1: value1
147-
option2: value2
148143
LastUpdated: %s`,
149144
timeutil.FormatToRFC3339(timestamp.Timestamp{Seconds: 1}))
150145
if out != expected {
151146
t.Errorf("Expected output:\n%s \nActual:\n%s \n", expected, out)
152147
}
153148
}
149+
150+
func TestPrintStorageWithOptions(t *testing.T) {
151+
storageDetail := &core.UIServiceTypes_StorageDetail{
152+
Spec: &specs.StorageSpec{
153+
Id: "REDIS1",
154+
Type: "redis",
155+
Options: map[string]string{
156+
"option1": "value1",
157+
"option2": "value2",
158+
},
159+
},
160+
LastUpdated: &timestamp.Timestamp{Seconds: 1},
161+
}
162+
out := PrintStorageDetail(storageDetail)
163+
164+
// Since map iteration order in Golang is radomized and "Options" is stored in a map,
165+
// this test just check that the output "contains" the key and value
166+
// rather than checking the exact match
167+
168+
expected := []string{
169+
"Id: REDIS1",
170+
"Type: redis",
171+
"Options:",
172+
" option1: value1",
173+
" option2: value2",
174+
fmt.Sprintf("LastUpdated: %s", timeutil.FormatToRFC3339(timestamp.Timestamp{Seconds: 1})),
175+
}
176+
177+
for _, want := range expected {
178+
if !strings.Contains(out, want) {
179+
t.Errorf("Missing \"%s\" from actual output\nActual output:\n%s", want, out)
180+
}
181+
}
182+
183+
}

0 commit comments

Comments
 (0)