MCPcopy
hub / github.com/grpc/grpc-go / TestNewFileWatcher

Method TestNewFileWatcher

authz/grpc_authz_server_interceptors_test.go:80–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func (s) TestNewFileWatcher(t *testing.T) {
81 tests := map[string]struct {
82 authzPolicy string
83 refreshDuration time.Duration
84 wantErr error
85 }{
86 "InvalidRefreshDurationFailsToCreateInterceptor": {
87 refreshDuration: time.Duration(0),
88 wantErr: fmt.Errorf("requires refresh interval(0s) greater than 0s"),
89 },
90 "InvalidPolicyFailsToCreateInterceptor": {
91 authzPolicy: `{}`,
92 refreshDuration: time.Duration(1),
93 wantErr: fmt.Errorf(`"name" is not present`),
94 },
95 "ValidPolicyCreatesInterceptor": {
96 authzPolicy: `{
97 "name": "authz",
98 "allow_rules":
99 [
100 {
101 "name": "allow_all"
102 }
103 ]
104 }`,
105 refreshDuration: time.Duration(1),
106 },
107 }
108 for name, test := range tests {
109 t.Run(name, func(t *testing.T) {
110 file := createTmpPolicyFile(t, name, []byte(test.authzPolicy))
111 i, err := authz.NewFileWatcher(file, test.refreshDuration)
112 if fmt.Sprint(err) != fmt.Sprint(test.wantErr) {
113 t.Fatalf("NewFileWatcher(%v) returned err: %v, want err: %v", test.authzPolicy, err, test.wantErr)
114 }
115 if i != nil {
116 i.Close()
117 }
118 })
119 }
120}

Callers

nothing calls this directly

Calls 5

NewFileWatcherFunction · 0.92
createTmpPolicyFileFunction · 0.85
ErrorfMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected