|
| 1 | +/* |
| 2 | +Copyright 2026 Cozystack contributors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package rest |
| 18 | + |
| 19 | +import ( |
| 20 | + "net/http" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/cozystack/blockstor/pkg/store" |
| 24 | +) |
| 25 | + |
| 26 | +// TestDRBDProxyEndpointsRespond: every DRBD-proxy endpoint we expose |
| 27 | +// returns 501 Not Implemented. Cozystack does not run DRBD proxy |
| 28 | +// (everything is on the same flat L2), but the linstor CLI calls |
| 29 | +// these and falling through to 404 is worse than an explicit 501. |
| 30 | +func TestDRBDProxyEndpointsRespond(t *testing.T) { |
| 31 | + base, stop := startServerWithStore(t, store.NewInMemory()) |
| 32 | + defer stop() |
| 33 | + |
| 34 | + cases := []struct { |
| 35 | + method string |
| 36 | + path string |
| 37 | + }{ |
| 38 | + {http.MethodPost, "/v1/resource-definitions/pvc-1/drbd-proxy/enable/n1/n2"}, |
| 39 | + {http.MethodPost, "/v1/resource-definitions/pvc-1/drbd-proxy/disable/n1/n2"}, |
| 40 | + {http.MethodPut, "/v1/resource-definitions/pvc-1/drbd-proxy"}, |
| 41 | + } |
| 42 | + |
| 43 | + for _, tc := range cases { |
| 44 | + req, _ := http.NewRequestWithContext(t.Context(), tc.method, base+tc.path, nil) |
| 45 | + |
| 46 | + resp, err := http.DefaultClient.Do(req) |
| 47 | + if err != nil { |
| 48 | + t.Fatalf("%s %s: %v", tc.method, tc.path, err) |
| 49 | + } |
| 50 | + _ = resp.Body.Close() |
| 51 | + |
| 52 | + if resp.StatusCode != http.StatusNotImplemented { |
| 53 | + t.Errorf("%s %s: status %d, want 501", tc.method, tc.path, resp.StatusCode) |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments