Skip to content

Commit 038ff32

Browse files
committed
feat(labels): add unit test for custom ranges
1 parent 456eec4 commit 038ff32

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN [[ $(ls -1 vendor/ | wc -l) -gt 0 ]] || (echo "Expected 'vendor' dependencie
1515
COPY cmd/ cmd/
1616
COPY pkg/ pkg/
1717

18-
COPY custom_ranges.json /etc/kubenetmon/custom_ranges.json
18+
COPY test/custom_ranges.json /etc/kubenetmon/custom_ranges.json
1919

2020
# Build
2121
ARG VERSION=dev

pkg/labeler/public_ranges_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,31 @@ func TestRefreshRemoteIPs(t *testing.T) {
279279
assert.Equal(t, "service1", detail.service)
280280
assert.Equal(t, "us-east-1", detail.region)
281281
})
282+
283+
t.Run("Test Custom az", func(t *testing.T) {
284+
custom := CustomIPRanges{
285+
Prefixes: []CustomPrefix{
286+
{IPPrefixStr: "10.1.1.16/32", Service: "redis", AvailabilityZone: "us-west-2a"},
287+
},
288+
}
289+
aws := AWSIPRanges{}
290+
gcp := GCPIPRanges{}
291+
google := GoogleIPRanges{}
292+
azure := AzureIPRanges{}
293+
294+
remoteIPRanges, trie, err := refreshRemoteIPs(aws, gcp, google, azure, custom)
295+
assert.NoError(t, err)
296+
assert.NotNil(t, remoteIPRanges)
297+
assert.NotNil(t, trie)
298+
299+
assert.Equal(t, 1, len(remoteIPRanges))
300+
ip, err := ipaddr.NewIPAddressString("10.1.1.16/32").ToAddress()
301+
assert.NoError(t, err)
302+
assert.NotNil(t, ip)
303+
detail := remoteIPRanges[ip.ToIPv4().ToKey()]
304+
assert.Equal(t, "redis", detail.service)
305+
assert.Equal(t, "us-west-2a", detail.az)
306+
})
282307
}
283308

284309
func TestNormalizeCloudString(t *testing.T) {

test/custom_ranges.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"syncToken": "1739569991",
3+
"createDate": "2025-02-14-21-53-11",
4+
"prefixes": [
5+
{
6+
"ip_prefix": "10.16.1.16/32",
7+
"az": "ap-southeast-2b",
8+
"service": "redis"
9+
}
10+
]
11+
}
12+

0 commit comments

Comments
 (0)