Skip to content

Commit 29c44ca

Browse files
Add a test for #1190 (#1193)
1 parent 317f204 commit 29c44ca

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lwcomponent/component_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,26 @@ func TestGetComponent(t *testing.T) {
112112
}
113113

114114
func TestLoadState(t *testing.T) {
115+
testLoadStateWithResponse(t, func(w http.ResponseWriter, r *http.Request) {
116+
fmt.Fprint(w, "{\"components\": [],\"version\": \"0.3.0\"}")
117+
})
118+
}
119+
120+
func TestLoadStateWithTwoFailures(t *testing.T) {
121+
failed := 0
122+
testLoadStateWithResponse(t, func(w http.ResponseWriter, r *http.Request) {
123+
if failed < 2 {
124+
failed += 1
125+
return
126+
}
127+
fmt.Fprint(w, "{\"components\": [],\"version\": \"0.3.0\"}")
128+
})
129+
}
130+
131+
func testLoadStateWithResponse(t *testing.T, response func(http.ResponseWriter, *http.Request)) {
115132
fakeServer := lacework.MockServer()
116133
fakeServer.UseApiV2()
117-
fakeServer.MockAPI(
118-
"Components",
119-
func(w http.ResponseWriter, r *http.Request) {
120-
fmt.Fprint(w, "{\"components\": [],\"version\": \"0.3.0\"}")
121-
},
122-
)
134+
fakeServer.MockAPI("Components", response)
123135
defer fakeServer.Close()
124136

125137
c, err := api.NewClient("test",

0 commit comments

Comments
 (0)