Improve qsdiff error reporting

This commit is contained in:
Thom Seddon 2019-04-15 12:03:31 +01:00
parent 091590d391
commit daec9f591a
2 changed files with 24 additions and 14 deletions

View File

@ -157,8 +157,9 @@ func TestGetLoginURL(t *testing.T) {
"state": []string{"nonce:http://example.com/hello"},
}
if !reflect.DeepEqual(qs, expectedQs) {
t.Error("Incorrect login query string:")
qsDiff(expectedQs, qs)
for _, err := range qsDiff(t, expectedQs, qs) {
t.Error(err)
}
}
//
@ -209,8 +210,9 @@ func TestGetLoginURL(t *testing.T) {
"state": []string{"nonce:http://example.com/hello"},
}
if !reflect.DeepEqual(qs, expectedQs) {
t.Error("Incorrect login query string:")
qsDiff(expectedQs, qs)
for _, err := range qsDiff(t, expectedQs, qs) {
t.Error(err)
}
}
//
@ -261,10 +263,13 @@ func TestGetLoginURL(t *testing.T) {
"state": []string{"nonce:http://example.com/hello"},
"prompt": []string{"consent select_account"},
}
qsDiff(expectedQs, qs)
for _, err := range qsDiff(t, expectedQs, qs) {
t.Error(err)
}
if !reflect.DeepEqual(qs, expectedQs) {
t.Error("Incorrect login query string:")
qsDiff(expectedQs, qs)
for _, err := range qsDiff(t, expectedQs, qs) {
t.Error(err)
}
}
//
@ -301,10 +306,13 @@ func TestGetLoginURL(t *testing.T) {
"state": []string{"nonce:http://another.com/hello"},
"prompt": []string{"consent select_account"},
}
qsDiff(expectedQs, qs)
for _, err := range qsDiff(t, expectedQs, qs) {
t.Error(err)
}
if !reflect.DeepEqual(qs, expectedQs) {
t.Error("Incorrect login query string:")
qsDiff(expectedQs, qs)
for _, err := range qsDiff(t, expectedQs, qs) {
t.Error(err)
}
}
}

View File

@ -75,20 +75,22 @@ func newHttpRequest(uri string) *http.Request {
return r
}
func qsDiff(one, two url.Values) {
func qsDiff(t *testing.T, one, two url.Values) []string {
errs := make([]string, 0)
for k := range one {
if two.Get(k) == "" {
fmt.Printf("Key missing: %s\n", k)
errs = append(errs, fmt.Sprintf("Key missing: %s", k))
}
if one.Get(k) != two.Get(k) {
fmt.Printf("Value different for %s: expected: '%s' got: '%s'\n", k, one.Get(k), two.Get(k))
errs = append(errs, fmt.Sprintf("Value different for %s: expected: '%s' got: '%s'", k, one.Get(k), two.Get(k)))
}
}
for k := range two {
if one.Get(k) == "" {
fmt.Printf("Extra key: %s\n", k)
errs = append(errs, fmt.Sprintf("Extra key: %s", k))
}
}
return errs
}
/**