(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func (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 | } |
nothing calls this directly
no test coverage detected