-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hwipl <33433250+hwipl@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package trafpol | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
// TestAllowDevsAdd tests Add of AllowDevs | ||
func TestAllowDevsAdd(t *testing.T) { | ||
a := NewAllowDevs() | ||
|
||
got := []string{} | ||
runNft = func(s string) { | ||
got = append(got, s) | ||
} | ||
|
||
// test adding | ||
want := []string{ | ||
"add element inet oc-daemon-filter allowdevs { eth3 }", | ||
} | ||
a.Add("eth3") | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("got %v, want %v", got, want) | ||
} | ||
|
||
// test adding again | ||
// should not change anything | ||
a.Add("eth3") | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("got %v, want %v", got, want) | ||
} | ||
} | ||
|
||
// TestAllowDevsRemove tests Remove of AllowDevs | ||
func TestAllowDevsRemove(t *testing.T) { | ||
a := NewAllowDevs() | ||
|
||
got := []string{} | ||
runNft = func(s string) { | ||
got = append(got, s) | ||
} | ||
|
||
// test removing device | ||
a.Add("eth3") | ||
want := []string{ | ||
"delete element inet oc-daemon-filter allowdevs { eth3 }", | ||
} | ||
got = []string{} | ||
a.Remove("eth3") | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("got %v, want %v", got, want) | ||
} | ||
|
||
// test removing again (not existing device) | ||
// should not change anything | ||
a.Remove("eth3") | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("got %v, want %v", got, want) | ||
} | ||
} | ||
|
||
// TestNewAllowDevs tests NewAllowDevs | ||
func TestNewAllowDevs(t *testing.T) { | ||
a := NewAllowDevs() | ||
if a.m == nil { | ||
t.Errorf("got nil, want != nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters