-
Notifications
You must be signed in to change notification settings - Fork 0
/
with_nic_test.go
52 lines (41 loc) · 1.14 KB
/
with_nic_test.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
43
44
45
46
47
48
49
50
51
52
package macpot_test
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/yitsushi/macpot"
)
func TestNew_WithNIC(t *testing.T) {
mac, err := macpot.New(
macpot.WithNIC("11:22:33"),
)
assert.NoError(t, err)
assert.Condition(t, func() bool {
re := regexp.MustCompile("^[a-z0-9]{2}(:[a-z0-9]{2}){2}:11:22:33$")
return re.Match([]byte(mac.ToString()))
}, "random generated MAC address is not valid: %s", mac.ToString())
}
func TestNew_WithNIC_short(t *testing.T) {
_, err := macpot.New(
macpot.WithNIC("11:22"),
)
assert.Error(t, err)
assert.ErrorAs(t, err, &macpot.NICError{})
assert.Equal(t, "invalid NIC: 11:22", err.Error())
}
func TestNew_WithNIC_long(t *testing.T) {
_, err := macpot.New(
macpot.WithNIC("11:22:33:44"),
)
assert.Error(t, err)
assert.ErrorAs(t, err, &macpot.NICError{})
assert.Equal(t, "invalid NIC: 11:22:33:44", err.Error())
}
func TestNew_WithNIC_invalidCharacter(t *testing.T) {
_, err := macpot.New(
macpot.WithNIC("11:2l:33"),
)
assert.Error(t, err)
assert.ErrorAs(t, err, &macpot.NICError{})
assert.Equal(t, "strconv.ParseInt: parsing \"2l\": invalid syntax", err.Error())
}