|
| 1 | +/* |
| 2 | + Copyright 2020 The Compose Specification Authors. |
| 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 transform |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/compose-spec/compose-go/v2/tree" |
| 23 | + "gotest.tools/v3/assert" |
| 24 | +) |
| 25 | + |
| 26 | +func TestNotExternal(t *testing.T) { |
| 27 | + ssh, err := transformMaybeExternal(map[string]any{ |
| 28 | + "driver": "foo", |
| 29 | + }, tree.NewPath("resources.test")) |
| 30 | + assert.NilError(t, err) |
| 31 | + assert.DeepEqual(t, ssh, map[string]any{ |
| 32 | + "driver": "foo", |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +func TestExternalNamed(t *testing.T) { |
| 37 | + ssh, err := transformMaybeExternal(map[string]any{ |
| 38 | + "external": true, |
| 39 | + "name": "foo", |
| 40 | + }, tree.NewPath("resources.test")) |
| 41 | + assert.NilError(t, err) |
| 42 | + assert.DeepEqual(t, ssh, map[string]any{ |
| 43 | + "external": true, |
| 44 | + "name": "foo", |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +func TestExternalUnnamed(t *testing.T) { |
| 49 | + ssh, err := transformMaybeExternal(map[string]any{ |
| 50 | + "external": true, |
| 51 | + }, tree.NewPath("resources.test")) |
| 52 | + assert.NilError(t, err) |
| 53 | + assert.DeepEqual(t, ssh, map[string]any{ |
| 54 | + "external": true, |
| 55 | + }) |
| 56 | +} |
| 57 | + |
| 58 | +func TestExternalLegacy(t *testing.T) { |
| 59 | + ssh, err := transformMaybeExternal(map[string]any{ |
| 60 | + "external": map[string]any{ |
| 61 | + "name": "foo", |
| 62 | + }, |
| 63 | + }, tree.NewPath("resources.test")) |
| 64 | + assert.NilError(t, err) |
| 65 | + assert.DeepEqual(t, ssh, map[string]any{ |
| 66 | + "external": true, |
| 67 | + "name": "foo", |
| 68 | + }) |
| 69 | +} |
| 70 | + |
| 71 | +func TestExternalLegacyNamed(t *testing.T) { |
| 72 | + ssh, err := transformMaybeExternal(map[string]any{ |
| 73 | + "external": map[string]any{ |
| 74 | + "name": "foo", |
| 75 | + }, |
| 76 | + "name": "foo", |
| 77 | + }, tree.NewPath("resources.test")) |
| 78 | + assert.NilError(t, err) |
| 79 | + assert.DeepEqual(t, ssh, map[string]any{ |
| 80 | + "external": true, |
| 81 | + "name": "foo", |
| 82 | + }) |
| 83 | +} |
0 commit comments