@@ -66,25 +66,29 @@ func TestFetchATrack(t *testing.T) {
6666}
6767
6868func TestFetchASpecificProblem (t * testing.T ) {
69- var (
70- APIKey = "mykey"
71- trackID = "go"
72- slug = "leap"
73- )
74- ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
75- trackProblemsAPI := fmt .Sprintf ("/v2/exercises/%s/%s" , trackID , slug )
76- assert .Equal (t , trackProblemsAPI , req .RequestURI )
69+ tests := []struct {
70+ key , url string
71+ }{
72+ {"" , "/v2/exercises/go/leap" },
73+ {"mykey" , "/v2/exercises/go/leap?key=mykey" },
74+ }
7775
78- if err := respondWithFixture (w , "problems.json" ); err != nil {
79- t .Fatal (err )
80- }
81- }))
82- defer ts .Close ()
76+ for _ , test := range tests {
8377
84- client := NewClient (& config.Config {XAPI : ts .URL , APIKey : APIKey })
78+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
79+ assert .Equal (t , test .url , req .RequestURI )
8580
86- _ , err := client .Fetch ([]string {trackID , slug })
87- assert .NoError (t , err )
81+ if err := respondWithFixture (w , "problems.json" ); err != nil {
82+ t .Fatal (err )
83+ }
84+ }))
85+ defer ts .Close ()
86+
87+ client := NewClient (& config.Config {XAPI : ts .URL , APIKey : test .key })
88+
89+ _ , err := client .Fetch ([]string {"go" , "leap" })
90+ assert .NoError (t , err )
91+ }
8892}
8993
9094func TestSkipProblem (t * testing.T ) {
0 commit comments