main
go 78 lines 1.66 KB
Raw
1 package route53
2
3 import (
4 "context"
5 "testing"
6 )
7
8 func TestFindHostedZoneIDExplicitOverride(t *testing.T) {
9 t.Parallel()
10
11 got, err := New(Config{HostedZoneID: "/hostedzone/Z123456789"}).findHostedZoneID(context.Background(), nil, "portal.example.com")
12 if err != nil {
13 t.Fatalf("findHostedZoneID() error = %v", err)
14 }
15 if got != "Z123456789" {
16 t.Fatalf("findHostedZoneID() = %q, want %q", got, "Z123456789")
17 }
18 }
19
20 func TestValidateConfig(t *testing.T) {
21 t.Parallel()
22
23 testCases := []struct {
24 name string
25 cfg Config
26 wantErr string
27 }{
28 {
29 name: "access key without secret",
30 cfg: Config{
31 AccessKeyID: "abc",
32 },
33 wantErr: "route53 access key id and secret access key must be supplied together",
34 },
35 {
36 name: "secret without access key",
37 cfg: Config{
38 SecretAccessKey: "def",
39 },
40 wantErr: "route53 access key id and secret access key must be supplied together",
41 },
42 {
43 name: "session token without static credentials",
44 cfg: Config{
45 SessionToken: "ghi",
46 },
47 wantErr: "route53 session token requires access key id and secret access key",
48 },
49 {
50 name: "valid static credentials",
51 cfg: Config{
52 AccessKeyID: "abc",
53 SecretAccessKey: "def",
54 SessionToken: "ghi",
55 },
56 },
57 {
58 name: "ambient credentials",
59 cfg: Config{},
60 },
61 }
62
63 for _, tc := range testCases {
64 t.Run(tc.name, func(t *testing.T) {
65 t.Parallel()
66
67 err := validateConfig(tc.cfg)
68 if tc.wantErr == "" && err != nil {
69 t.Fatalf("validateConfig() error = %v", err)
70 }
71 if tc.wantErr != "" {
72 if err == nil || err.Error() != tc.wantErr {
73 t.Fatalf("validateConfig() error = %v, want %q", err, tc.wantErr)
74 }
75 }
76 })
77 }
78 }