File: endpoint_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (123 lines) | stat: -rw-r--r-- 2,730 bytes parent folder | download | duplicates (5)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package endpointdiscovery

import (
	"net/url"
	"reflect"
	"strconv"
	"testing"
	"time"
)

func Test_cloneURL(t *testing.T) {
	tests := []struct {
		value     *url.URL
		wantClone *url.URL
	}{
		{
			value: &url.URL{
				Scheme:      "https",
				Opaque:      "foo",
				User:        nil,
				Host:        "amazonaws.com",
				Path:        "/",
				RawPath:     "/",
				ForceQuery:  true,
				RawQuery:    "thing=value",
				Fragment:    "1234",
				RawFragment: "1234",
			},
			wantClone: &url.URL{
				Scheme:      "https",
				Opaque:      "foo",
				User:        nil,
				Host:        "amazonaws.com",
				Path:        "/",
				RawPath:     "/",
				ForceQuery:  true,
				RawQuery:    "thing=value",
				Fragment:    "1234",
				RawFragment: "1234",
			},
		},
		{
			value: &url.URL{
				Scheme:      "https",
				Opaque:      "foo",
				User:        url.UserPassword("NOT", "VALID"),
				Host:        "amazonaws.com",
				Path:        "/",
				RawPath:     "/",
				ForceQuery:  true,
				RawQuery:    "thing=value",
				Fragment:    "1234",
				RawFragment: "1234",
			},
			wantClone: &url.URL{
				Scheme:      "https",
				Opaque:      "foo",
				User:        url.UserPassword("NOT", "VALID"),
				Host:        "amazonaws.com",
				Path:        "/",
				RawPath:     "/",
				ForceQuery:  true,
				RawQuery:    "thing=value",
				Fragment:    "1234",
				RawFragment: "1234",
			},
		},
	}
	for i, tt := range tests {
		t.Run(strconv.Itoa(i), func(t *testing.T) {
			gotClone := cloneURL(tt.value)
			if gotClone == tt.value {
				t.Errorf("expct clone URL to not be same pointer address")
			}
			if tt.value.User != nil {
				if tt.value.User == gotClone.User {
					t.Errorf("expct cloned Userinfo to not be same pointer address")
				}
			}
			if !reflect.DeepEqual(gotClone, tt.wantClone) {
				t.Errorf("cloneURL() = %v, want %v", gotClone, tt.wantClone)
			}
		})
	}
}

func TestEndpoint_Prune(t *testing.T) {
	endpoint := Endpoint{}

	endpoint.Add(WeightedAddress{
		URL:     &url.URL{},
		Expired: time.Now().Add(5 * time.Minute),
	})

	initial := endpoint.Addresses

	if e, a := false, endpoint.Prune(); e != a {
		t.Errorf("expect prune %v, got %v", e, a)
	}

	if e, a := &initial[0], &endpoint.Addresses[0]; e != a {
		t.Errorf("expect slice address to be same")
	}

	endpoint.Add(WeightedAddress{
		URL:     &url.URL{},
		Expired: time.Now().Add(5 * -time.Minute),
	})

	initial = endpoint.Addresses

	if e, a := true, endpoint.Prune(); e != a {
		t.Errorf("expect prune %v, got %v", e, a)
	}

	if e, a := &initial[0], &endpoint.Addresses[0]; e == a {
		t.Errorf("expect slice address to be different")
	}

	if e, a := 1, endpoint.Len(); e != a {
		t.Errorf("expect slice length %v, got %v", e, a)
	}
}