MCPcopy
hub / github.com/spacecloud-io/space-cloud / TestGetFileRule

Function TestGetFileRule

gateway/modules/auth/handle_file_test.go:14–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestGetFileRule(t *testing.T) {
15
16 var ps = "/"
17
18 fileRule := &config.FileRule{
19 Prefix: ps,
20 Rule: map[string]*config.Rule{"rule": &config.Rule{Rule: "allow"}},
21 }
22 fileRule1 := &config.FileRule{
23 Prefix: ps + "folder",
24 Rule: map[string]*config.Rule{"rule": &config.Rule{Rule: "allow"}},
25 }
26 fileRule2 := &config.FileRule{
27 Prefix: ps + "folder/:suyash",
28 Rule: map[string]*config.Rule{"rule": &config.Rule{Rule: "allow"}},
29 }
30 fileRule3 := &config.FileRule{
31 Prefix: ps + "folder/suyash",
32 Rule: map[string]*config.Rule{"rule": &config.Rule{Rule: "deny"}},
33 }
34
35 var mod = []struct {
36 module *Module
37 IsErrExpected bool
38 testName string
39 path string
40 pathParams map[string]interface{}
41 result *config.FileRule
42 }{
43 {
44 testName: "Valid Test Case-Basic Path", IsErrExpected: false,
45 result: &config.FileRule{ID: "", Prefix: "/", Rule: map[string]*config.Rule{"rule": {Rule: "allow"}}},
46 pathParams: map[string]interface{}{}, path: ps,
47 module: &Module{fileRules: []*config.FileRule{fileRule, fileRule, fileRule}},
48 },
49 {
50 testName: "Test Case-local file store type", IsErrExpected: false, path: ps,
51 module: &Module{fileRules: []*config.FileRule{fileRule, fileRule, fileRule}, fileStoreType: "local"},
52 pathParams: map[string]interface{}{},
53 result: &config.FileRule{ID: "", Prefix: "/", Rule: map[string]*config.Rule{"rule": {Rule: "allow"}}},
54 },
55 {
56 testName: "Valid Test Case-File Rule with folder specified", IsErrExpected: false, path: ps + "folder",
57 module: &Module{fileRules: []*config.FileRule{fileRule1, fileRule1, fileRule1}},
58 pathParams: map[string]interface{}{},
59 result: &config.FileRule{ID: "", Prefix: "/folder", Rule: map[string]*config.Rule{"rule": {Rule: "allow"}}},
60 },
61 {
62 testName: "Valid Test Case-Folder with variable mentioned", IsErrExpected: false, path: ps + "folder/:suyash",
63 module: &Module{fileRules: []*config.FileRule{fileRule2, fileRule2, fileRule2}},
64 result: &config.FileRule{ID: "", Prefix: "/folder/:suyash", Rule: map[string]*config.Rule{"rule": {Rule: "allow"}}},
65 pathParams: map[string]interface{}{"suyash": ":suyash"},
66 },
67 {
68 testName: "Test case-Rule and Actual Path do not match", IsErrExpected: true, path: ps + "folder" + ps + "file",
69 module: &Module{fileRules: []*config.FileRule{fileRule3, fileRule3, fileRule3}},
70 },
71 {

Callers

nothing calls this directly

Calls 2

getFileRuleMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected