|
3 | 3 | package system // import "github.com/docker/docker/integration/system" |
4 | 4 |
|
5 | 5 | import ( |
| 6 | + "encoding/json" |
| 7 | + "io" |
| 8 | + "net/http" |
6 | 9 | "testing" |
7 | 10 |
|
8 | 11 | "github.com/docker/docker/client" |
| 12 | + "github.com/docker/docker/testutil/request" |
9 | 13 | "gotest.tools/v3/assert" |
10 | 14 | is "gotest.tools/v3/assert/cmp" |
11 | 15 | ) |
@@ -47,3 +51,56 @@ func TestInfoBinaryCommits(t *testing.T) { |
47 | 51 | assert.Check(t, is.Equal(info.RuncCommit.Expected, info.RuncCommit.ID)) //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.49. |
48 | 52 | }) |
49 | 53 | } |
| 54 | + |
| 55 | +func TestInfoLegacyFields(t *testing.T) { |
| 56 | + ctx := setupTest(t) |
| 57 | + |
| 58 | + const notPresent = "expected field to not be present" |
| 59 | + |
| 60 | + tests := []struct { |
| 61 | + name string |
| 62 | + url string |
| 63 | + expectedFields map[string]any |
| 64 | + }{ |
| 65 | + { |
| 66 | + name: "api v1.49 legacy bridge-nftables", |
| 67 | + url: "/v1.49/info", |
| 68 | + expectedFields: map[string]any{ |
| 69 | + "BridgeNfIp6tables": false, |
| 70 | + "BridgeNfIptables": false, |
| 71 | + }, |
| 72 | + }, |
| 73 | + { |
| 74 | + name: "api v1.50 legacy bridge-nftables", |
| 75 | + url: "/v1.50/info", |
| 76 | + expectedFields: map[string]any{ |
| 77 | + "BridgeNfIp6tables": notPresent, |
| 78 | + "BridgeNfIptables": notPresent, |
| 79 | + }, |
| 80 | + }, |
| 81 | + } |
| 82 | + for _, tc := range tests { |
| 83 | + t.Run(tc.name, func(t *testing.T) { |
| 84 | + res, _, err := request.Get(ctx, tc.url) |
| 85 | + assert.NilError(t, err) |
| 86 | + assert.Equal(t, res.StatusCode, http.StatusOK) |
| 87 | + body, err := io.ReadAll(res.Body) |
| 88 | + assert.NilError(t, err) |
| 89 | + |
| 90 | + actual := map[string]any{} |
| 91 | + err = json.Unmarshal(body, &actual) |
| 92 | + assert.NilError(t, err, string(body)) |
| 93 | + |
| 94 | + for field, expectedValue := range tc.expectedFields { |
| 95 | + if expectedValue == notPresent { |
| 96 | + _, found := actual[field] |
| 97 | + assert.Assert(t, !found, "field %s should not be present", field) |
| 98 | + } else { |
| 99 | + _, found := actual[field] |
| 100 | + assert.Assert(t, found, "field %s should be present", field) |
| 101 | + assert.Check(t, is.DeepEqual(actual[field], expectedValue)) |
| 102 | + } |
| 103 | + } |
| 104 | + }) |
| 105 | + } |
| 106 | +} |
0 commit comments