(t *testing.T)
| 49 | } |
| 50 | |
| 51 | func TestWithCacheShardLevelPaths(t *testing.T) { |
| 52 | t.Parallel() |
| 53 | tests := []struct { |
| 54 | name string |
| 55 | path string |
| 56 | shard request.Shard |
| 57 | cluster *request.Cluster |
| 58 | wantStatus int |
| 59 | wantNextCalled bool |
| 60 | }{ |
| 61 | { |
| 62 | name: "non-shard path passes through", |
| 63 | path: "/apis/apis.kcp.io/v1alpha1/apiexports", |
| 64 | shard: request.Shard("amber"), |
| 65 | cluster: &request.Cluster{Name: logicalcluster.Name("ws-1234")}, |
| 66 | wantStatus: http.StatusOK, |
| 67 | wantNextCalled: true, |
| 68 | }, |
| 69 | { |
| 70 | name: "metrics with no shard and no cluster passes through", |
| 71 | path: "/metrics", |
| 72 | wantStatus: http.StatusOK, |
| 73 | wantNextCalled: true, |
| 74 | }, |
| 75 | { |
| 76 | name: "metrics with shard set is rejected with 501", |
| 77 | path: "/metrics", |
| 78 | shard: request.Shard("amber"), |
| 79 | wantStatus: http.StatusNotImplemented, |
| 80 | wantNextCalled: false, |
| 81 | }, |
| 82 | { |
| 83 | name: "metrics with cluster set is rejected with 501", |
| 84 | path: "/metrics", |
| 85 | cluster: &request.Cluster{Name: logicalcluster.Name("ws-1234")}, |
| 86 | wantStatus: http.StatusNotImplemented, |
| 87 | wantNextCalled: false, |
| 88 | }, |
| 89 | { |
| 90 | name: "metrics with both shard and cluster set is rejected", |
| 91 | path: "/metrics", |
| 92 | shard: request.Shard("amber"), |
| 93 | cluster: &request.Cluster{Name: logicalcluster.Name("ws-1234")}, |
| 94 | wantStatus: http.StatusNotImplemented, |
| 95 | wantNextCalled: false, |
| 96 | }, |
| 97 | } |
| 98 | |
| 99 | for _, tc := range tests { |
| 100 | t.Run(tc.name, func(t *testing.T) { |
| 101 | t.Parallel() |
| 102 | nextCalled := false |
| 103 | next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 104 | nextCalled = true |
| 105 | w.WriteHeader(http.StatusOK) |
| 106 | }) |
| 107 | |
| 108 | h := WithCacheShardLevelPaths(next) |
nothing calls this directly
no test coverage detected