refractor: add initial go internall pkg module.

This commit is contained in:
Alexandre Pujol 2023-04-16 23:26:46 +01:00
parent ef8029e086
commit 049b939349
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
4 changed files with 289 additions and 0 deletions

57
pkg/util/tools_test.go Normal file
View file

@ -0,0 +1,57 @@
// apparmor.d - Full set of apparmor profiles
// Copyright (C) 2023 Alexandre Pujol <alexandre@pujol.io>
// SPDX-License-Identifier: GPL-2.0-only
package util
import (
"reflect"
"testing"
)
func TestDecodeHex(t *testing.T) {
tests := []struct {
name string
str string
want string
}{
{
name: "Hexa",
str: "666F6F20626172",
want: "foo bar",
},
{
name: "Not Hexa",
str: "ALLOWED",
want: "ALLOWED",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := DecodeHex(tt.str); got != tt.want {
t.Errorf("DecodeHex() = %v, want %v", got, tt.want)
}
})
}
}
func TestRemoveDuplicate(t *testing.T) {
tests := []struct {
name string
inlist []string
want []string
}{
{
name: "Duplicate",
inlist: []string{"foo", "bar", "foo", "bar", ""},
want: []string{"foo", "bar"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := RemoveDuplicate(tt.inlist); !reflect.DeepEqual(got, tt.want) {
t.Errorf("RemoveDuplicate() = %v, want %v", got, tt.want)
}
})
}
}