summaryrefslogtreecommitdiff
path: root/lib/lib_test.go
blob: e58be1b17ffb8a9bd61a815429103c3a507c420f (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package lib

import (
	"testing"
)

func TestActionConstants(t *testing.T) {
	tests := []struct {
		action Action
		want   string
	}{
		{ActionAdd, "add"},
		{ActionRemove, "remove"},
		{ActionOutput, "output"},
	}

	for _, tt := range tests {
		if string(tt.action) != tt.want {
			t.Errorf("Action constant = %s, want %s", tt.action, tt.want)
		}
	}
}

func TestIPTypeConstants(t *testing.T) {
	tests := []struct {
		ipType IPType
		want   string
	}{
		{IPv4, "ipv4"},
		{IPv6, "ipv6"},
	}

	for _, tt := range tests {
		if string(tt.ipType) != tt.want {
			t.Errorf("IPType constant = %s, want %s", tt.ipType, tt.want)
		}
	}
}

func TestCaseRemoveConstants(t *testing.T) {
	if CaseRemovePrefix != 0 {
		t.Errorf("CaseRemovePrefix = %d, want 0", CaseRemovePrefix)
	}
	if CaseRemoveEntry != 1 {
		t.Errorf("CaseRemoveEntry = %d, want 1", CaseRemoveEntry)
	}
}

func TestActionsRegistry(t *testing.T) {
	if !ActionsRegistry[ActionAdd] {
		t.Error("ActionAdd should be registered")
	}
	if !ActionsRegistry[ActionRemove] {
		t.Error("ActionRemove should be registered")
	}
	if !ActionsRegistry[ActionOutput] {
		t.Error("ActionOutput should be registered")
	}
	if ActionsRegistry["unknown"] {
		t.Error("unknown action should not be registered")
	}
}

func TestIgnoreIPv4(t *testing.T) {
	ipType := IgnoreIPv4()
	if ipType != IPv4 {
		t.Errorf("IgnoreIPv4() = %s, want %s", ipType, IPv4)
	}
}

func TestIgnoreIPv6(t *testing.T) {
	ipType := IgnoreIPv6()
	if ipType != IPv6 {
		t.Errorf("IgnoreIPv6() = %s, want %s", ipType, IPv6)
	}
}

func TestIgnoreIPOption(t *testing.T) {
	// Test that IgnoreIPOption functions return correct types
	var opt4 IgnoreIPOption = IgnoreIPv4
	var opt6 IgnoreIPOption = IgnoreIPv6

	if opt4() != IPv4 {
		t.Errorf("IgnoreIPv4 option returned %s, want %s", opt4(), IPv4)
	}
	if opt6() != IPv6 {
		t.Errorf("IgnoreIPv6 option returned %s, want %s", opt6(), IPv6)
	}
}