Skip to content

Commit 6ad2958

Browse files
committed
add cascade test
1 parent 3e27032 commit 6ad2958

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

acceptance/lookup_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,29 @@ func TestLookupNamespaceless(t *testing.T) {
106106
expected := fixtures.LookupNamespacelessResult
107107
assert.Equal(t, expected, *actual)
108108
}
109+
110+
func TestLookupNamespacelessCascade(t *testing.T) {
111+
if v := os.Getenv("JERAKIA_ACC"); v == "" {
112+
t.Skip("JERAKIA_ACC not set")
113+
}
114+
115+
client, err := NewClient()
116+
if err != nil {
117+
t.Fatal(err)
118+
}
119+
120+
lookupOpts := &jerakia.LookupOpts{
121+
LookupType: "cascade",
122+
Metadata: map[string]string{
123+
"env": "dev",
124+
},
125+
}
126+
127+
actual, err := jerakia.Lookup(client, "biscuits", lookupOpts)
128+
if err != nil {
129+
t.Fatal(err)
130+
}
131+
132+
expected := fixtures.LookupNamespacelessCascadeResult
133+
assert.Equal(t, expected, *actual)
134+
}

testing/lookup_fixtures.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,50 @@ func HandleLookupNamespaceless(t *testing.T) {
144144
fmt.Fprintf(w, LookupNamespacelessResponse)
145145
})
146146
}
147+
148+
// LookupNamespacelessCascadeResponse is the expected response of a cascading
149+
// namespace-less lookup.
150+
const LookupNamespacelessCascadeResponse = `
151+
{
152+
"found": true,
153+
"payload": [
154+
[
155+
"gingernuts",
156+
"jammiedodgers",
157+
"custardcreams"
158+
],
159+
[
160+
"richtea",
161+
"digestive"
162+
]
163+
],
164+
"status": "ok"
165+
}
166+
`
167+
168+
// LookupNamespacelessCascadeResult is the expected result of a cascading
169+
// namespace-less lookup.
170+
var LookupNamespacelessCascadeResult = jerakia.LookupResult{
171+
Status: "ok",
172+
Found: true,
173+
Payload: []interface{}{
174+
[]interface{}{
175+
"gingernuts", "jammiedodgers", "custardcreams",
176+
},
177+
[]interface{}{
178+
"richtea", "digestive",
179+
},
180+
},
181+
}
182+
183+
// HandleLookupNamespacelessCascade tests a cascading namespace-less lookup.
184+
func HandleLookupNamespacelessCascade(t *testing.T) {
185+
th.Mux.HandleFunc("/lookup/biscuits", func(w http.ResponseWriter, r *http.Request) {
186+
assert.Equal(t, r.Method, "GET")
187+
assert.Equal(t, r.Header.Get("X-Authentication"), fake.Token)
188+
189+
w.Header().Set("Content-Type", "application/json")
190+
w.WriteHeader(http.StatusOK)
191+
fmt.Fprintf(w, LookupNamespacelessCascadeResponse)
192+
})
193+
}

testing/lookup_requests_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,24 @@ func TestLookupNamespaceless(t *testing.T) {
8686
expected := LookupNamespacelessResult
8787
assert.Equal(t, expected, *actual)
8888
}
89+
90+
func TestLookupNamespacelessCascade(t *testing.T) {
91+
th.SetupHTTP()
92+
defer th.TeardownHTTP()
93+
HandleLookupNamespacelessCascade(t)
94+
95+
lookupOpts := &jerakia.LookupOpts{
96+
LookupType: "cascade",
97+
Metadata: map[string]string{
98+
"env": "dev",
99+
},
100+
}
101+
102+
actual, err := jerakia.Lookup(fake.FakeClient(), "biscuits", lookupOpts)
103+
if err != nil {
104+
t.Fatal(err)
105+
}
106+
107+
expected := LookupNamespacelessCascadeResult
108+
assert.Equal(t, expected, *actual)
109+
}

0 commit comments

Comments
 (0)