|
| 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 | + "encoding/json" |
| 21 | + "net/http" |
| 22 | + "testing" |
| 23 | + |
| 24 | + "github.com/cozystack/blockstor/pkg/store" |
| 25 | +) |
| 26 | + |
| 27 | +// TestNodeConnectionsReturnEmpty pins the contract: list and per-pair |
| 28 | +// node-connections both 200 with `[]`. golinstor's polling loop logs an |
| 29 | +// error for any non-200, so the empty-but-present shape is what keeps |
| 30 | +// the controller log clean for cozystack's flat-L2 setup where there |
| 31 | +// are no inter-satellite tunnels to report. |
| 32 | +func TestNodeConnectionsReturnEmpty(t *testing.T) { |
| 33 | + base, stop := startServerWithStore(t, store.NewInMemory()) |
| 34 | + defer stop() |
| 35 | + |
| 36 | + for _, path := range []string{ |
| 37 | + "/v1/node-connections", |
| 38 | + "/v1/node-connections/n1/n2", |
| 39 | + } { |
| 40 | + resp := httpGet(t, base+path) |
| 41 | + |
| 42 | + if resp.StatusCode != http.StatusOK { |
| 43 | + _ = resp.Body.Close() |
| 44 | + t.Errorf("%s status: got %d, want 200", path, resp.StatusCode) |
| 45 | + |
| 46 | + continue |
| 47 | + } |
| 48 | + |
| 49 | + var got []map[string]any |
| 50 | + |
| 51 | + err := json.NewDecoder(resp.Body).Decode(&got) |
| 52 | + _ = resp.Body.Close() |
| 53 | + |
| 54 | + if err != nil { |
| 55 | + t.Errorf("%s decode: %v", path, err) |
| 56 | + |
| 57 | + continue |
| 58 | + } |
| 59 | + |
| 60 | + if len(got) != 0 { |
| 61 | + t.Errorf("%s body: got %d entries, want 0", path, len(got)) |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments