Skip to content

Commit 22fa3d4

Browse files
committed
Add a step to verify if all fields in the struct have the url tag
1 parent f09fe9d commit 22fa3d4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

github/github_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,23 @@ func testJSONMarshal(t *testing.T, v interface{}, want string) {
169169
}
170170
}
171171

172-
func testAddOptions(t *testing.T, url string, v interface{}, want string) {
172+
// Test whether the v fields have the url tag and the parsing of v
173+
// produces query parameters that corresponds to the want string.
174+
func testAddURLOptions(t *testing.T, url string, v interface{}, want string) {
173175
t.Helper()
174176

177+
vt := reflect.Indirect(reflect.ValueOf(v)).Type()
178+
for i := 0; i < vt.NumField(); i++ {
179+
field := vt.Field(i)
180+
if alias, ok := field.Tag.Lookup("url"); ok {
181+
if alias == "" {
182+
t.Errorf("The field %+v has a blank url tag", field)
183+
}
184+
} else {
185+
t.Errorf("The field %+v has no url tag specified", field)
186+
}
187+
}
188+
175189
got, err := addOptions(url, v)
176190
if err != nil {
177191
t.Errorf("Unable to add %#v as query parameters", v)

github/scim_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ func TestListSCIMProvisionedIdentitiesOptions_addOptions(t *testing.T) {
434434

435435
url := "some/path"
436436

437-
testAddOptions(t, url, &ListSCIMProvisionedIdentitiesOptions{}, url)
437+
testAddURLOptions(t, url, &ListSCIMProvisionedIdentitiesOptions{}, url)
438438

439-
testAddOptions(
439+
testAddURLOptions(
440440
t,
441441
url,
442442
&ListSCIMProvisionedIdentitiesOptions{
@@ -446,7 +446,7 @@ func TestListSCIMProvisionedIdentitiesOptions_addOptions(t *testing.T) {
446446
fmt.Sprintf("%s?count=10&startIndex=1", url),
447447
)
448448

449-
testAddOptions(
449+
testAddURLOptions(
450450
t,
451451
url,
452452
&ListSCIMProvisionedIdentitiesOptions{

0 commit comments

Comments
 (0)