2024-03-25 23:37:30 +01:00
|
|
|
// apparmor.d - Full set of apparmor profiles
|
|
|
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
2024-10-02 17:22:46 +02:00
|
|
|
package prebuild
|
2024-03-25 23:37:30 +01:00
|
|
|
|
|
|
|
import (
|
2024-09-26 23:05:47 +02:00
|
|
|
"slices"
|
2024-03-25 23:37:30 +01:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBase_Helpers(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
b Base
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "base",
|
2024-09-26 23:05:47 +02:00
|
|
|
b: Base{Keyword: "test", Help: []string{"test"}, Msg: "test"},
|
2024-03-25 23:37:30 +01:00
|
|
|
want: "test",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := tt.b.Name(); got != tt.want {
|
|
|
|
t.Errorf("Base.Name() = %v, want %v", got, tt.want)
|
|
|
|
}
|
2024-09-26 23:05:47 +02:00
|
|
|
if got := tt.b.Usage(); !slices.Equal(got, []string{tt.want}) {
|
2024-03-25 23:37:30 +01:00
|
|
|
t.Errorf("Base.Usage() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
if got := tt.b.Message(); got != tt.want {
|
|
|
|
t.Errorf("Base.Message() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHelp(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
tasks map[string]Base
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "one",
|
|
|
|
tasks: map[string]Base{
|
2024-09-26 23:05:47 +02:00
|
|
|
"one": {Keyword: "one", Help: []string{"one"}, Msg: "one"},
|
|
|
|
"two": {Keyword: "two", Help: []string{"two"}, Msg: "two"},
|
2024-03-25 23:37:30 +01:00
|
|
|
},
|
|
|
|
want: `one`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := Help(tt.name, tt.tasks); !strings.Contains(got, tt.want) {
|
|
|
|
t.Errorf("Help() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|