forked from juju/juju
/
ipchecker.go
42 lines (34 loc) · 869 Bytes
/
ipchecker.go
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
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package testing
import (
"fmt"
"net"
gc "gopkg.in/check.v1"
)
type ipsEqualChecker struct {
*gc.CheckerInfo
}
var IPsEqual gc.Checker = &ipsEqualChecker{
&gc.CheckerInfo{Name: "IPsEqual", Params: []string{"obtained", "expected"}},
}
func (c *ipsEqualChecker) Check(params []interface{}, name []string) (bool, string) {
ips1, ok := params[0].([]net.IP)
if !ok {
return false, "param 0 is not of type []net.IP"
}
ips2, ok := params[1].([]net.IP)
if !ok {
return false, "param 0 is not of type []net.IP"
}
if len(ips1) != len(ips2) {
return false, fmt.Sprintf("legnth of ip slices not equal %d != %d",
len(ips1), len(ips2))
}
for i := range ips1 {
if !ips1[i].Equal(ips2[i]) {
return false, "ip slices are not equal"
}
}
return true, ""
}