-
Notifications
You must be signed in to change notification settings - Fork 227
/
group_sub_tests.go
50 lines (44 loc) · 1.38 KB
/
group_sub_tests.go
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
package group_sub_tests
import (
"encoding/json"
"testing"
"github.com/Telmate/proxmox-api-go/proxmox"
cliTest "github.com/Telmate/proxmox-api-go/test/cli"
"github.com/stretchr/testify/require"
)
// Default CLEANUP test for Group
func Cleanup(t *testing.T, group proxmox.GroupName) {
Test := &cliTest.Test{
ReqErr: true,
ErrContains: string(group),
Args: []string{"-i", "delete", "group", string(group)},
}
Test.StandardTest(t)
}
// Default DELETE test for Group
func Delete(t *testing.T, group proxmox.GroupName) {
Test := &cliTest.Test{
Contains: []string{string(group)},
Args: []string{"-i", "delete", "group", string(group)},
}
Test.StandardTest(t)
}
// Default GET test for Group
func Get(t *testing.T, group proxmox.ConfigGroup) {
Test := &cliTest.Test{
Args: []string{"-i", "get", "group", string(group.Name)},
}
Get_Test(t, group, Test.StandardTest(t))
}
// Custom test as require.JSONEq() wont work here due to *[]UserID being an unordered list
func Get_Test(t *testing.T, expected proxmox.ConfigGroup, actualRaw []byte) {
actual := proxmox.ConfigGroup{}
require.NoError(t, json.Unmarshal(actualRaw, &actual))
require.Equal(t, expected.Name, actual.Name)
require.Equal(t, expected.Comment, actual.Comment)
if expected.Members != nil && actual.Members != nil {
require.ElementsMatch(t, *expected.Members, *actual.Members)
} else {
t.FailNow()
}
}