Skip to content

Commit 4e4e72e

Browse files
authored
chore: add extends unit test (#1661)
* chore: add extends unit test * add reset/override tests
1 parent df8a7ce commit 4e4e72e

File tree

8 files changed

+312
-23
lines changed

8 files changed

+312
-23
lines changed

defang.code-workspace

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
{
2-
"folders": [
3-
{
4-
"path": "."
5-
},
6-
{
7-
"path": "src"
8-
}
9-
],
10-
"settings": {
11-
"go.testEnvVars": {
12-
"AWS_PROFILE": "defang-sandbox"
13-
},
14-
"go.buildTags": "integration",
15-
"go.testFlags": ["-short"],
16-
"go.testTimeout": "300s",
17-
"makefile.configureOnOpen": false
18-
}
19-
}
2+
"folders": [
3+
{
4+
"path": "."
5+
},
6+
{
7+
"path": "src"
8+
}
9+
],
10+
"settings": {
11+
"yaml.customTags": [
12+
"!reset mapping",
13+
"!reset sequence",
14+
"!reset scalar",
15+
"!reset null",
16+
"!override mapping",
17+
"!override sequence"
18+
],
19+
"go.testEnvVars": {
20+
"AWS_PROFILE": "defang-sandbox"
21+
},
22+
"go.buildTags": "integration",
23+
"go.testFlags": ["-short"],
24+
"go.testTimeout": "300s",
25+
"makefile.configureOnOpen": false
26+
}
27+
}

src/pkg/cli/compose/validation_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func TestValidationAndConvert(t *testing.T) {
3232
if err != nil {
3333
return nil, err
3434
}
35-
3635
return configs.Names, nil
3736
}
3837

@@ -49,12 +48,12 @@ func TestValidationAndConvert(t *testing.T) {
4948

5049
if err := FixupServices(t.Context(), mockClient, project, UploadModeIgnore); err != nil {
5150
t.Logf("Service conversion failed: %v", err)
52-
logs.WriteString(err.Error() + "\n")
51+
logs.WriteString("Error: " + err.Error() + "\n") // no coverage!
5352
}
5453

5554
if err := ValidateProjectConfig(t.Context(), project, listConfigNamesFunc); err != nil {
5655
t.Logf("Project config validation failed: %v", err)
57-
logs.WriteString(err.Error() + "\n")
56+
logs.WriteString("Error: " + err.Error() + "\n")
5857
}
5958

6059
mode := modes.ModeAffordable
@@ -63,7 +62,7 @@ func TestValidationAndConvert(t *testing.T) {
6362
}
6463
if err := ValidateProject(project, mode); err != nil {
6564
t.Logf("Project validation failed: %v", err)
66-
logs.WriteString(err.Error() + "\n")
65+
logs.WriteString("Error: " + err.Error() + "\n") // no coverage!
6766
}
6867

6968
// The order of the services is not guaranteed, so we sort the logs before comparing
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
array-env:
3+
image: bogus
4+
environment:
5+
- WITH_VALUE=foo
6+
- EMPTY_VALUE=
7+
- NO_VALUE
8+
- BASE_ONLY=foo
9+
map-env:
10+
image: bogus
11+
environment:
12+
WITH_VALUE: foo
13+
EMPTY_VALUE: ""
14+
NO_VALUE:
15+
BASE_ONLY: foo

src/testdata/extends/compose.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
services:
2+
array-set:
3+
extends:
4+
file: ./compose.base.yaml
5+
service: array-env
6+
environment:
7+
- WITH_VALUE=bar
8+
- EMPTY_VALUE=bar
9+
- NO_VALUE=bar
10+
- NEW_VALUE=bar
11+
12+
map-set:
13+
extends:
14+
file: ./compose.base.yaml
15+
service: map-env
16+
environment:
17+
WITH_VALUE: bar
18+
EMPTY_VALUE: bar
19+
NO_VALUE: bar
20+
NEW_VALUE: bar
21+
22+
array-unset:
23+
extends:
24+
file: ./compose.base.yaml
25+
service: array-env
26+
environment:
27+
- WITH_VALUE
28+
- EMPTY_VALUE
29+
- NO_VALUE
30+
- NEW_VALUE
31+
32+
map-unset:
33+
extends:
34+
file: ./compose.base.yaml
35+
service: map-env
36+
environment:
37+
WITH_VALUE:
38+
EMPTY_VALUE:
39+
NO_VALUE:
40+
NEW_VALUE:
41+
42+
array-reset:
43+
extends:
44+
file: ./compose.base.yaml
45+
service: array-env
46+
environment: !reset []
47+
48+
map-reset:
49+
extends:
50+
file: ./compose.base.yaml
51+
service: map-env
52+
environment:
53+
WITH_VALUE: !reset
54+
EMPTY_VALUE: !reset
55+
NO_VALUE: !reset
56+
NEW_VALUE: !reset
57+
58+
array-override:
59+
extends:
60+
file: ./compose.base.yaml
61+
service: array-env
62+
environment: !override
63+
- WITH_VALUE=bar
64+
- EMPTY_VALUE=bar
65+
- NO_VALUE=bar
66+
- NEW_VALUE=bar
67+
68+
map-override:
69+
extends:
70+
file: ./compose.base.yaml
71+
service: map-env
72+
environment: !override
73+
WITH_VALUE: bar
74+
EMPTY_VALUE: bar
75+
NO_VALUE: bar
76+
NEW_VALUE: bar
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"array-override": {
3+
"command": null,
4+
"entrypoint": null,
5+
"environment": {
6+
"EMPTY_VALUE": "bar",
7+
"NEW_VALUE": "bar",
8+
"NO_VALUE": "bar",
9+
"WITH_VALUE": "bar"
10+
},
11+
"image": "bogus",
12+
"networks": {
13+
"default": null
14+
}
15+
},
16+
"array-reset": {
17+
"command": null,
18+
"entrypoint": null,
19+
"image": "bogus",
20+
"networks": {
21+
"default": null
22+
}
23+
},
24+
"array-set": {
25+
"command": null,
26+
"entrypoint": null,
27+
"environment": {
28+
"BASE_ONLY": "foo",
29+
"EMPTY_VALUE": "bar",
30+
"NEW_VALUE": "bar",
31+
"NO_VALUE": "bar",
32+
"WITH_VALUE": "bar"
33+
},
34+
"image": "bogus",
35+
"networks": {
36+
"default": null
37+
}
38+
},
39+
"array-unset": {
40+
"command": null,
41+
"entrypoint": null,
42+
"environment": {
43+
"BASE_ONLY": "foo",
44+
"EMPTY_VALUE": null,
45+
"NEW_VALUE": null,
46+
"NO_VALUE": null,
47+
"WITH_VALUE": null
48+
},
49+
"image": "bogus",
50+
"networks": {
51+
"default": null
52+
}
53+
},
54+
"map-override": {
55+
"command": null,
56+
"entrypoint": null,
57+
"environment": {
58+
"EMPTY_VALUE": "bar",
59+
"NEW_VALUE": "bar",
60+
"NO_VALUE": "bar",
61+
"WITH_VALUE": "bar"
62+
},
63+
"image": "bogus",
64+
"networks": {
65+
"default": null
66+
}
67+
},
68+
"map-reset": {
69+
"command": null,
70+
"entrypoint": null,
71+
"environment": {
72+
"BASE_ONLY": "foo"
73+
},
74+
"image": "bogus",
75+
"networks": {
76+
"default": null
77+
}
78+
},
79+
"map-set": {
80+
"command": null,
81+
"entrypoint": null,
82+
"environment": {
83+
"BASE_ONLY": "foo",
84+
"EMPTY_VALUE": "bar",
85+
"NEW_VALUE": "bar",
86+
"NO_VALUE": "bar",
87+
"WITH_VALUE": "bar"
88+
},
89+
"image": "bogus",
90+
"networks": {
91+
"default": null
92+
}
93+
},
94+
"map-unset": {
95+
"command": null,
96+
"entrypoint": null,
97+
"environment": {
98+
"BASE_ONLY": "foo",
99+
"EMPTY_VALUE": null,
100+
"NEW_VALUE": null,
101+
"NO_VALUE": null,
102+
"WITH_VALUE": null
103+
},
104+
"image": "bogus",
105+
"networks": {
106+
"default": null
107+
}
108+
}
109+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: extends
2+
services:
3+
array-override:
4+
environment:
5+
EMPTY_VALUE: bar
6+
NEW_VALUE: bar
7+
NO_VALUE: bar
8+
WITH_VALUE: bar
9+
image: bogus
10+
networks:
11+
default: null
12+
array-reset:
13+
image: bogus
14+
networks:
15+
default: null
16+
array-set:
17+
environment:
18+
BASE_ONLY: foo
19+
EMPTY_VALUE: bar
20+
NEW_VALUE: bar
21+
NO_VALUE: bar
22+
WITH_VALUE: bar
23+
image: bogus
24+
networks:
25+
default: null
26+
array-unset:
27+
environment:
28+
BASE_ONLY: foo
29+
EMPTY_VALUE: null
30+
NEW_VALUE: null
31+
NO_VALUE: null
32+
WITH_VALUE: null
33+
image: bogus
34+
networks:
35+
default: null
36+
map-override:
37+
environment:
38+
EMPTY_VALUE: bar
39+
NEW_VALUE: bar
40+
NO_VALUE: bar
41+
WITH_VALUE: bar
42+
image: bogus
43+
networks:
44+
default: null
45+
map-reset:
46+
environment:
47+
BASE_ONLY: foo
48+
image: bogus
49+
networks:
50+
default: null
51+
map-set:
52+
environment:
53+
BASE_ONLY: foo
54+
EMPTY_VALUE: bar
55+
NEW_VALUE: bar
56+
NO_VALUE: bar
57+
WITH_VALUE: bar
58+
image: bogus
59+
networks:
60+
default: null
61+
map-unset:
62+
environment:
63+
BASE_ONLY: foo
64+
EMPTY_VALUE: null
65+
NEW_VALUE: null
66+
NO_VALUE: null
67+
WITH_VALUE: null
68+
image: bogus
69+
networks:
70+
default: null
71+
networks:
72+
default:
73+
name: extends_default
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! service "array-override": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
2+
! service "array-reset": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
3+
! service "array-set": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
4+
! service "array-unset": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
5+
! service "map-override": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
6+
! service "map-reset": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
7+
! service "map-set": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
8+
! service "map-unset": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
9+
Error: missing configs ["EMPTY_VALUE" "NEW_VALUE" "NO_VALUE" "WITH_VALUE"] (https://docs.defang.io/docs/concepts/configuration)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
! Environment variable "NODE_ENV" is ignored; add it to `.env` if needed
22
! Environment variable "NODE_ENV" is ignored; add it to `.env` or it may be resolved from config during deployment
33
! service "interpolate": missing memory reservation; using provider-specific defaults. Specify deploy.resources.reservations.memory to avoid out-of-memory errors
4-
missing configs ["NODE_ENV" "POSTGRES_PASSWORD" "def"] (https://docs.defang.io/docs/concepts/configuration)
4+
Error: missing configs ["NODE_ENV" "POSTGRES_PASSWORD" "def"] (https://docs.defang.io/docs/concepts/configuration)

0 commit comments

Comments
 (0)