@@ -6,6 +6,8 @@ package api
6
6
import (
7
7
"encoding/json"
8
8
"testing"
9
+
10
+ "github.com/aws/aws-sdk-go/private/util"
9
11
)
10
12
11
13
func buildAPI () * API {
@@ -238,80 +240,77 @@ func TestExampleGeneration(t *testing.T) {
238
240
def .API = a
239
241
240
242
def .setup ()
241
- expected := `
242
- import (
243
+ expected := `import (
244
+ "bytes"
243
245
"fmt"
244
- "strings"
245
246
"time"
246
247
247
- "` + SDKImportRoot + `/aws"
248
- "` + SDKImportRoot + `/aws/awserr"
249
- "` + SDKImportRoot + `/aws/session"
250
- "` + SDKImportRoot + `/service/fooservice"
251
-
248
+ "github.com/aws/aws-sdk-go/aws"
249
+ "github.com/aws/aws-sdk-go/aws/session"
250
+ "github.com/aws/aws-sdk-go/service/fooservice"
252
251
)
253
252
254
253
var _ time.Duration
255
- var _ strings.Reader
256
- var _ aws.Config
254
+ var _ bytes.Buffer
257
255
258
- func parseTime(layout, value string) *time.Time {
259
- t, err := time.Parse(layout, value)
260
- if err != nil {
261
- panic(err)
262
- }
263
- return &t
264
- }
256
+ func ExampleFooService_Foo() {
257
+ sess := session.Must(session.NewSession())
265
258
266
- // I pity the foo
267
- //
268
- // Foo bar baz qux
269
- func ExampleFooService_Foo_shared00() {
270
- svc := fooservice.New(session.New())
271
- input := &fooservice.FooInput{
272
- BarShape: aws.String("Hello world"),
259
+ svc := fooservice.New(sess)
260
+
261
+ params := &fooservice.FooInput{
262
+ BarShape: aws.String("string"),
273
263
ComplexField: &fooservice.ComplexShape{
274
- Field: aws.String("bar "),
264
+ Field: aws.String("string "),
275
265
List: []*fooservice.NestedComplexShape{
276
- {
277
- NestedField: aws.String("qux "),
266
+ &fooservice.NestedComplexShape{ // Required
267
+ NestedField: aws.String("string "),
278
268
},
269
+ // More values...
279
270
},
280
271
},
281
272
ListField: []*fooservice.ComplexShape{
282
- {
283
- Field: aws.String("baz"),
273
+ &fooservice.ComplexShape{ // Required
274
+ Field: aws.String("string"),
275
+ List: []*fooservice.NestedComplexShape{
276
+ &fooservice.NestedComplexShape{ // Required
277
+ NestedField: aws.String("string"),
278
+ },
279
+ // More values...
280
+ },
284
281
},
282
+ // More values...
285
283
},
286
284
ListsField: [][]*fooservice.ComplexShape{
287
- {
288
- {
289
- Field: aws.String("baz"),
285
+ []*fooservice.ComplexShape{ // Required
286
+ &fooservice.ComplexShape{ // Required
287
+ Field: aws.String("string"),
288
+ List: []*fooservice.NestedComplexShape{
289
+ &fooservice.NestedComplexShape{ // Required
290
+ NestedField: aws.String("string"),
291
+ },
292
+ // More values...
293
+ },
290
294
},
295
+ // More values...
291
296
},
297
+ // More values...
292
298
},
293
299
}
300
+ resp, err := svc.Foo(params)
294
301
295
- result, err := svc.Foo(input)
296
302
if err != nil {
297
- if aerr, ok := err.(awserr.Error); ok {
298
- switch aerr.Code() {
299
- default:
300
- fmt.Println(aerr.Error())
301
- }
302
- } else {
303
- // Print the error, cast err to awserr.Error to get the Code and
304
- // Message from an error.
305
- fmt.Println(err.Error())
306
- }
303
+ // Print the error, cast err to awserr.Error to get the Code and
304
+ // Message from an error.
305
+ fmt.Println(err.Error())
307
306
return
308
307
}
309
308
310
- fmt.Println(result)
311
- }
312
- `
313
- if expected != a . ExamplesGoCode () {
314
- t .Errorf ("Expected :\n %s\n Received :\n %s\n " , expected , a . ExamplesGoCode () )
309
+ // Pretty-print the response data.
310
+ fmt.Println(resp)
311
+ } `
312
+ if e , a := util . GoFmt ( expected ), util . GoFmt ( a . ExampleGoCode ()); e != a {
313
+ t .Errorf ("Expect :\n %s\n Actual :\n %s\n " , e , a )
315
314
}
316
315
}
317
316
0 commit comments