-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaws_test.go
58 lines (49 loc) · 1.08 KB
/
aws_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package aws
import (
"encoding/xml"
"fmt"
"testing"
)
func TestDoError(t *testing.T) {
v, err := DescribeInstances()
if err != nil {
t.Fatal(err)
}
t.Logf("%#v", v)
}
func TestUnmarshalError(t *testing.T) {
body := []byte(`
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Errors>
<Error>
<Code>AuthFailure</Code>
<Message>AWS was not able to validate the provided access credentials</Message>
</Error>
</Errors>
<RequestID>afc00dc9-0c19-46db-a987-f7de2a12a361</RequestID>
</Response>
`)
type Error struct {
Code string
Message string
}
type Response struct {
RequestId string `xml:"RequestID"`
Errors []Error `xml:"Errors>Error"`
}
got := new(Response)
err := xml.Unmarshal(body, got)
if err != nil {
t.Fatal(err)
}
exp := &Response{
RequestId: "afc00dc9-0c19-46db-a987-f7de2a12a361",
Errors: []Error{
{Code: "AuthFailure", Message: "AWS was not able to validate the provided access credentials"},
},
}
if fmt.Sprintf("%#v", exp) != fmt.Sprintf("%#v", got) {
t.Fatalf("Expected %#v, but got %#v", exp, got)
}
}