Skip to content

Commit

Permalink
Refactor expansion level tests to use test grid
Browse files Browse the repository at this point in the history
  • Loading branch information
brandur committed Jul 28, 2017
1 parent c402575 commit 1c3d7ad
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/base64"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -116,36 +117,50 @@ func TestGetValidator_NoSuitableParameter(t *testing.T) {
}

func TestParseExpansionLevel(t *testing.T) {
assert.Equal(t,
&ExpansionLevel{expansions: map[string]*ExpansionLevel{
"charge": nil,
"customer": nil,
}},
ParseExpansionLevel([]string{"charge", "customer"}))

assert.Equal(t,
&ExpansionLevel{expansions: map[string]*ExpansionLevel{
"charge": {expansions: map[string]*ExpansionLevel{
testCases := []struct {
expansions []string
want *ExpansionLevel
}{
{
[]string{"charge", "customer"},
&ExpansionLevel{expansions: map[string]*ExpansionLevel{
"charge": nil,
"customer": nil,
"source": nil,
}},
"customer": nil,
}},
ParseExpansionLevel([]string{"charge.customer", "customer", "charge.source"}))

assert.Equal(t,
&ExpansionLevel{expansions: map[string]*ExpansionLevel{
"charge": {expansions: map[string]*ExpansionLevel{
"customer": {expansions: map[string]*ExpansionLevel{
"default_source": nil,
},
{
[]string{"charge.customer", "customer", "charge.source"},
&ExpansionLevel{expansions: map[string]*ExpansionLevel{
"charge": {expansions: map[string]*ExpansionLevel{
"customer": nil,
"source": nil,
}},
"customer": nil,
}},
}},
ParseExpansionLevel([]string{"charge.customer.default_source", "charge"}))

assert.Equal(t,
&ExpansionLevel{expansions: map[string]*ExpansionLevel{}, wildcard: true},
ParseExpansionLevel([]string{"*"}))
},
{
[]string{"charge.customer.default_source", "charge"},
&ExpansionLevel{expansions: map[string]*ExpansionLevel{
"charge": {expansions: map[string]*ExpansionLevel{
"customer": {expansions: map[string]*ExpansionLevel{
"default_source": nil,
}},
}},
}},
},
{
[]string{"*"},
&ExpansionLevel{
expansions: map[string]*ExpansionLevel{},
wildcard: true,
},
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%+v", tc.expansions), func(t *testing.T) {
assert.Equal(t, tc.want, ParseExpansionLevel(tc.expansions))
})
}
}

func TestValidateAuth(t *testing.T) {
Expand Down

0 comments on commit 1c3d7ad

Please sign in to comment.