File: update_endpoint_internal_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 (76 lines) | stat: -rw-r--r-- 1,769 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
package customizations

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

func TestRemoveBucketFromPath(t *testing.T) {
	cases := []struct {
		url      url.URL
		bucket   string
		expected string
	}{
		{
			url: url.URL{
				Scheme:  "https",
				Host:    "amazonaws.com",
				Path:    "/bucket-name/key/path",
				RawPath: "/bucket-name/key/path",
			},
			bucket:   "bucket-name",
			expected: "https://amazonaws.com/key/path",
		},
		{
			url: url.URL{
				Scheme:  "https",
				Host:    "amazonaws.com",
				Path:    "/bucket-name/key/path/with/bucket-name",
				RawPath: "/bucket-name/key/path/with/bucket-name",
			},
			bucket:   "bucket-name",
			expected: "https://amazonaws.com/key/path/with/bucket-name",
		},
		{
			url: url.URL{
				Scheme:  "https",
				Host:    "amazonaws.com",
				Path:    "/arn:aws:s3:us-east-1:012345678901:accesspoint:myap/key/path?isEscaped=true",
				RawPath: "/arn%3Aaws%3As3%3Aus-east-1%3A012345678901%3Aaccesspoint%3Amyap/key/path%3FisEscaped%3Dtrue",
			},
			bucket:   "arn:aws:s3:us-east-1:012345678901:accesspoint:myap",
			expected: "https://amazonaws.com/key/path%3FisEscaped%3Dtrue",
		},
		{
			url: url.URL{
				Scheme:  "https",
				Host:    "amazonaws.com",
				Path:    "/path/to/key",
				RawPath: "/path/to/key",
			},
			bucket:   "not-a-match",
			expected: "https://amazonaws.com/path/to/key",
		},
		{
			url: url.URL{
				Scheme:  "https",
				Host:    "amazonaws.com",
				Path:    "",
				RawPath: "",
			},
			bucket:   "not-a-match",
			expected: "https://amazonaws.com/",
		},
	}

	for i, tt := range cases {
		t.Run(strconv.Itoa(i), func(t *testing.T) {
			removeBucketFromPath(&tt.url, tt.bucket)

			if e, a := tt.expected, tt.url.String(); e != a {
				t.Errorf("expect %v, got %v", e, a)
			}
		})
	}
}