-
Notifications
You must be signed in to change notification settings - Fork 0
/
revoke_test.go
76 lines (66 loc) · 1.37 KB
/
revoke_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package influxqb
import (
"fmt"
"github.com/influxdata/influxql"
"github.com/stretchr/testify/assert"
"testing"
)
/*
*/
var testRevokeBuilder = []struct {
d string
b BuilderIf
s string
e bool
}{
{"Revoke Read on all for user",
NewRevokeBuilder().
FromUsername("Usr").
WithPrivilege(influxql.ReadPrivilege).
OnDatabase("db"),
"REVOKE READ ON db FROM Usr",
false,
},
{"Revoke write on db for user",
NewRevokeBuilder().
FromUsername("Usr").
WithPrivilege(influxql.WritePrivilege).
OnDatabase("db"),
"REVOKE WRITE ON db FROM Usr",
false,
},
{"Revoke All on db for user ",
NewRevokeBuilder().
FromUsername("Usr").
WithPrivilege(influxql.AllPrivileges).
OnDatabase("db"),
"REVOKE ALL PRIVILEGES ON db FROM Usr",
false,
},
{"Revoke no privilege on db ",
NewRevokeBuilder().
FromUsername("Usr").
WithPrivilege(influxql.NoPrivileges).
OnDatabase("db"),
"REVOKE NO PRIVILEGES ON db FROM Usr",
false,
},
{"Revoke Admin on db",
NewRevokeBuilder().Admin().FromUsername("Usr"),
"REVOKE ALL PRIVILEGES FROM Usr",
false,
},
}
func TestRevokeBuilder(t *testing.T) {
for i, sample := range testRevokeBuilder {
s, err := sample.b.Build()
fmt.Print("Test ", i, ": ", sample.d)
if sample.e {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, sample.s, s)
fmt.Println(" [OK]")
}
}