-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup_test.go
53 lines (44 loc) · 1.04 KB
/
lookup_test.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
51
52
53
package main
import (
"os/user"
"strings"
"testing"
)
var currentUser, _ = user.Current()
func TestLookupGroup(t *testing.T) {
groupById, err := LookupGroupById(currentUser.Gid)
if err != nil {
t.Error(err.Error())
}
groupByName, err := LookupGroupByName(groupById.Name)
if err != nil {
t.Error(err.Error())
}
if groupById.Name != groupByName.Name {
t.Errorf("the lookups did not return the same group, %v != %v", groupById, groupByName)
}
}
func TestLookupGroupById_errors(t *testing.T) {
_, err := LookupGroupById("ddddd")
if err == nil {
t.Error("error expected")
}
_, err = LookupGroupById("1010101010")
if err == nil {
t.Error("error expected")
}
}
func TestLookupGroupByName_errors(t *testing.T) {
groupName := "notExistingGroupName"
_, err := LookupGroupByName(groupName)
if err == nil {
t.Error("error expected")
}
if !strings.Contains(err.Error(), groupName) {
t.Errorf("error should contain group name, error: %s", err.Error())
}
_, err = LookupGroupByName("")
if err == nil {
t.Error("error expected")
}
}