-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_test.go
More file actions
84 lines (75 loc) · 2.24 KB
/
show_test.go
File metadata and controls
84 lines (75 loc) · 2.24 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"reflect"
"testing"
)
func TestParseGetfaclOutput(t *testing.T) {
output := `# file: testdir/
# owner: alice
# group: dev
user::rwx
user:bob:r-x
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:bob:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
`
expected := &FilePermissions{
Target: "testdir/",
Owner: "alice",
Group: "dev",
Entries: []PermissionEntry{
{Type: "user", Entity: "", Permissions: "rwx", Source: "standard"},
{Type: "user", Entity: "bob", Permissions: "r-x", Source: "acl"},
{Type: "group", Entity: "", Permissions: "r-x", Source: "standard"},
{Type: "mask", Entity: "", Permissions: "rwx", Source: "acl"},
{Type: "other", Entity: "", Permissions: "r-x", Source: "standard"},
{Type: "default:user", Entity: "", Permissions: "rwx", Source: "default"},
{Type: "default:user", Entity: "bob", Permissions: "rwx", Source: "default"},
{Type: "default:group", Entity: "", Permissions: "r-x", Source: "default"},
{Type: "default:mask", Entity: "", Permissions: "rwx", Source: "default"},
{Type: "default:other", Entity: "", Permissions: "r-x", Source: "default"},
},
}
got, err := ParseGetfaclOutput(output)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Parsed result mismatch.\nGot: %+v\nWant: %+v", got, expected)
}
}
func TestParseGetfaclOutput_WithCommentsAndTabs(t *testing.T) {
output := `# file: testfile
# owner: root
# group: root
user::rw-
user:alice:rwx #effective:r-x
group::r-x
mask::r-x
other::r--
`
expected := &FilePermissions{
Target: "testfile",
Owner: "root",
Group: "root",
Entries: []PermissionEntry{
{Type: "user", Entity: "", Permissions: "rw-", Source: "standard"},
{Type: "user", Entity: "alice", Permissions: "rwx", Source: "acl"},
{Type: "group", Entity: "", Permissions: "r-x", Source: "standard"},
{Type: "mask", Entity: "", Permissions: "r-x", Source: "acl"},
{Type: "other", Entity: "", Permissions: "r--", Source: "standard"},
},
}
got, err := ParseGetfaclOutput(output)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Parsed result mismatch.\nGot: %+v\nWant: %+v", got, expected)
}
}