Skip to content

Commit

Permalink
test(utils): add test for is permitted ip address
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed Nov 29, 2024
1 parent 62cd641 commit 54b81e6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/PaloAltoNetworks/pango v0.10.2 h1:Tjn6vIzzAq6Dd7N0mDuiP8w8pz8k5W9zz/TTSUQCsQY=
github.com/PaloAltoNetworks/pango v0.10.2/go.mod h1:GztcRnVLur7G+VFG7Z5ZKNFgScLtsycwPMp1qVebE5g=
github.com/bl4ko/go-devicetype-library v0.1.10 h1:OJtTK1SXNbROn1M9XTmcpCJKkAsgvshX65ba9FiwcB0=
github.com/bl4ko/go-devicetype-library v0.1.10/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.11 h1:LGEseX0ATje/5YcUKpyCNb8bJEUrCCGV5Qmmon2flLE=
github.com/bl4ko/go-devicetype-library v0.1.11/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY=
Expand Down
60 changes: 60 additions & 0 deletions internal/utils/networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,63 @@ func TestRemoveZoneIndexFromIPAddress(t *testing.T) {
})
}
}

func Test_subnetsContainIPAddress(t *testing.T) {
type args struct {
ipAddress string
subnets []string
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := subnetsContainIPAddress(tt.args.ipAddress, tt.args.subnets); got != tt.want {
t.Errorf("subnetsContainIPAddress() = %v, want %v", got, tt.want)
}
})
}
}

func TestIsPermittedIPAddress(t *testing.T) {
type args struct {
ipAddress string
permittedSubnets []string
ignoredSubnets []string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Test permitted ip address",
args: args{
ipAddress: "172.25.17.2",
permittedSubnets: []string{"172.0.0.0/8"},
ignoredSubnets: []string{},
},
want: true,
},
{
name: "Test unpermitted ip address",
args: args{
ipAddress: "172.25.17.2",
permittedSubnets: []string{},
ignoredSubnets: []string{"172.0.0.0/8"},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsPermittedIPAddress(tt.args.ipAddress, tt.args.permittedSubnets, tt.args.ignoredSubnets); got != tt.want {
t.Errorf("IsPermittedIPAddress() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 54b81e6

Please sign in to comment.