File: cache_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 662,428 kB
  • sloc: java: 16,875; makefile: 432; sh: 175
file content (46 lines) | stat: -rw-r--r-- 930 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
package endpointdiscovery

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

func TestEndpointCache_Get_prune(t *testing.T) {
	c := NewEndpointCache(2)
	c.Add(Endpoint{
		Key: "foo",
		Addresses: []WeightedAddress{
			{
				URL: &url.URL{
					Host: "foo.amazonaws.com",
				},
				Expired: time.Now().Add(5 * time.Minute),
			},
			{
				URL: &url.URL{
					Host: "bar.amazonaws.com",
				},
				Expired: time.Now().Add(5 * -time.Minute),
			},
		},
	})

	load, _ := c.endpoints.Load("foo")
	if ev := load.(Endpoint); len(ev.Addresses) != 2 {
		t.Errorf("expected two weighted addresses")
	}

	weightedAddress, ok := c.Get("foo")
	if !ok {
		t.Errorf("expect weighted address, got none")
	}
	if e, a := "foo.amazonaws.com", weightedAddress.URL.Host; e != a {
		t.Errorf("expect %v, got %v", e, a)
	}

	load, _ = c.endpoints.Load("foo")
	if ev := load.(Endpoint); len(ev.Addresses) != 1 {
		t.Errorf("expected one weighted address")
	}
}