@@ -104,3 +104,58 @@ func TestPetShopListFailed(t *testing.T) {
104104 ),
105105 )
106106}
107+
108+ func TestPetShopLookup (t * testing.T ) {
109+ ctrl := gomock .NewController (t )
110+ defer ctrl .Finish ()
111+
112+ mpf := mock .NewMockPetFetcher (ctrl )
113+ mpf .EXPECT ().LookupPet (
114+ gomock .Any (),
115+ gomock .Eq ("A01" ),
116+ ).Return (mock .Pets [0 ], nil )
117+
118+ service := http .NewPetShopAPI (mpf , nil )
119+ httpd := µmock .Endpoint (service .Lookup ())
120+ yield := httpd (µmock .Input (
121+ µmock .Method ("GET" ),
122+ µmock .URL ("/petshop/pets/A01" ),
123+ µmock .Header ("Accept" , "application/json" ),
124+ ))
125+
126+ it .Then (t ).Should (
127+ it .Equiv (yield ,
128+ ø .Status .OK (
129+ ø .ContentType .ApplicationJSON ,
130+ ø .Send (api .NewPet (mock .Pets [0 ])),
131+ ),
132+ ),
133+ )
134+ }
135+
136+ func TestPetShopCreate (t * testing.T ) {
137+ ctrl := gomock .NewController (t )
138+ defer ctrl .Finish ()
139+
140+ mpc := mock .NewMockPetCreator (ctrl )
141+ mpc .EXPECT ().CreatePet (
142+ gomock .Any (),
143+ gomock .Eq (mock .Pets [0 ]),
144+ ).Return (nil )
145+
146+ service := http .NewPetShopAPI (nil , mpc )
147+ httpd := µmock .Endpoint (service .Create ())
148+ yield := httpd (µmock .Input (
149+ µmock .Method ("POST" ),
150+ µmock .URL ("/petshop/pets" ),
151+ µmock .Header ("Accept" , "application/json" ),
152+ µmock .Header ("Authorization" , "Basic cGV0c3RvcmU6b3duZXIK" ),
153+ µmock .JSON (mock .Pets [0 ]),
154+ ))
155+
156+ it .Then (t ).Should (
157+ it .Equiv (yield ,
158+ ø .Status .Created (),
159+ ),
160+ )
161+ }
0 commit comments