This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move address range helpers into address package
This means that users don't drag in a dependency on aws-sdk.
- Loading branch information
Showing
5 changed files
with
51 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package address | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
r0to127 = cidr2("10.0.0.0", "10.0.0.127") | ||
r128to255 = cidr2("10.0.0.128", "10.0.0.255") | ||
r0to255 = cidr2("10.0.0.0", "10.0.0.255") | ||
r1dot0to255 = cidr2("10.0.1.0", "10.0.1.255") | ||
r2dot0to255 = cidr2("10.0.2.0", "10.0.2.255") | ||
) | ||
|
||
func TestRemoveCommon(t *testing.T) { | ||
a := []CIDR{r0to127, r1dot0to255} | ||
b := []CIDR{r1dot0to255, r2dot0to255} | ||
newA, newB := RemoveCommon(a, b) | ||
require.Equal(t, []CIDR{r0to127}, newA) | ||
require.Equal(t, []CIDR{r2dot0to255}, newB) | ||
} | ||
|
||
func TestMerge(t *testing.T) { | ||
ranges := []Range{ | ||
r0to127.Range(), | ||
r128to255.Range(), | ||
r2dot0to255.Range(), | ||
} | ||
require.Equal(t, []Range{r0to255.Range(), r2dot0to255.Range()}, Merge(ranges)) | ||
} | ||
|
||
// Helper | ||
|
||
// [start; end] | ||
func cidr2(start, end string) CIDR { | ||
c := Range{Start: ip(start), End: ip(end) + 1}.CIDRs() | ||
if len(c) != 1 { | ||
panic("invalid cidr") | ||
} | ||
return c[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters