summaryrefslogtreecommitdiff
path: root/lib/lib_test.go
blob: 0f2f5cecbabf4e95d632ca8acef4a652561ec779 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package lib

import (
	"testing"
)

func TestConstants(t *testing.T) {
	if ActionAdd != "add" {
		t.Errorf("expected ActionAdd to be 'add', got %q", ActionAdd)
	}
	if ActionRemove != "remove" {
		t.Errorf("expected ActionRemove to be 'remove', got %q", ActionRemove)
	}
	if ActionOutput != "output" {
		t.Errorf("expected ActionOutput to be 'output', got %q", ActionOutput)
	}
	if IPv4 != "ipv4" {
		t.Errorf("expected IPv4 to be 'ipv4', got %q", IPv4)
	}
	if IPv6 != "ipv6" {
		t.Errorf("expected IPv6 to be 'ipv6', got %q", IPv6)
	}
	if CaseRemovePrefix != 0 {
		t.Errorf("expected CaseRemovePrefix to be 0, got %d", CaseRemovePrefix)
	}
	if CaseRemoveEntry != 1 {
		t.Errorf("expected CaseRemoveEntry to be 1, got %d", CaseRemoveEntry)
	}
}

func TestActionsRegistry(t *testing.T) {
	expected := map[Action]bool{
		ActionAdd:    true,
		ActionRemove: true,
		ActionOutput: true,
	}
	for action, val := range expected {
		if ActionsRegistry[action] != val {
			t.Errorf("expected ActionsRegistry[%q] to be %v", action, val)
		}
	}
	if len(ActionsRegistry) != len(expected) {
		t.Errorf("expected ActionsRegistry to have %d entries, got %d", len(expected), len(ActionsRegistry))
	}
}

func TestIgnoreIPv4(t *testing.T) {
	result := IgnoreIPv4()
	if result != IPv4 {
		t.Errorf("expected IgnoreIPv4() to return IPv4, got %q", result)
	}
}

func TestIgnoreIPv6(t *testing.T) {
	result := IgnoreIPv6()
	if result != IPv6 {
		t.Errorf("expected IgnoreIPv6() to return IPv6, got %q", result)
	}
}

func TestIgnoreIPOptionType(t *testing.T) {
	var opt IgnoreIPOption = IgnoreIPv4
	if opt() != IPv4 {
		t.Error("IgnoreIPOption function should return IPv4")
	}
	opt = IgnoreIPv6
	if opt() != IPv6 {
		t.Error("IgnoreIPOption function should return IPv6")
	}
}