Skip to content

Commit df29b8a

Browse files
ndeloofglours
authored andcommitted
replace tests based on a huge "full" example and use tests dedicated to each attribute
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 9dee8f4 commit df29b8a

File tree

82 files changed

+4964
-3034
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4964
-3034
lines changed

loader/full-example.yml

Lines changed: 0 additions & 461 deletions
This file was deleted.

loader/full-struct_test.go

Lines changed: 0 additions & 1742 deletions
This file was deleted.

loader/loader_test.go

Lines changed: 0 additions & 765 deletions
Large diffs are not rendered by default.

loader/tests/annotations_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 tests
18+
19+
import (
20+
"testing"
21+
22+
"github.com/compose-spec/compose-go/v2/types"
23+
"gotest.tools/v3/assert"
24+
)
25+
26+
func TestAnnotations(t *testing.T) {
27+
p := load(t, `
28+
name: test
29+
services:
30+
list:
31+
image: alpine
32+
annotations:
33+
- com.example.foo=bar
34+
map:
35+
image: alpine
36+
annotations:
37+
com.example.foo: bar
38+
`)
39+
expect := func(p *types.Project) {
40+
expected := types.Mapping{"com.example.foo": "bar"}
41+
assert.DeepEqual(t, p.Services["list"].Annotations, expected)
42+
assert.DeepEqual(t, p.Services["map"].Annotations, expected)
43+
}
44+
expect(p)
45+
46+
yamlP, jsonP := roundTrip(t, p)
47+
expect(yamlP)
48+
expect(jsonP)
49+
}

loader/tests/attach_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 tests
18+
19+
import (
20+
"testing"
21+
22+
"github.com/compose-spec/compose-go/v2/types"
23+
"gotest.tools/v3/assert"
24+
)
25+
26+
func TestAttach(t *testing.T) {
27+
p := load(t, `
28+
name: test
29+
services:
30+
attached:
31+
image: alpine
32+
attach: true
33+
detached:
34+
image: alpine
35+
attach: false
36+
default:
37+
image: alpine
38+
`)
39+
40+
expect := func(p *types.Project) {
41+
assert.Equal(t, *p.Services["attached"].Attach, true)
42+
assert.Equal(t, *p.Services["detached"].Attach, false)
43+
assert.Assert(t, p.Services["default"].Attach == nil)
44+
}
45+
expect(p)
46+
47+
yamlP, jsonP := roundTrip(t, p)
48+
expect(yamlP)
49+
expect(jsonP)
50+
}

loader/tests/blkio_config_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 tests
18+
19+
import (
20+
"testing"
21+
22+
"github.com/compose-spec/compose-go/v2/types"
23+
"gotest.tools/v3/assert"
24+
)
25+
26+
func TestBlkioConfig(t *testing.T) {
27+
p := load(t, `
28+
name: test
29+
services:
30+
foo:
31+
image: busybox
32+
blkio_config:
33+
weight: 300
34+
weight_device:
35+
- path: /dev/sda
36+
weight: 400
37+
device_read_bps:
38+
- path: /dev/sda
39+
rate: 1024k
40+
device_write_bps:
41+
- path: /dev/sda
42+
rate: 1024
43+
device_read_iops:
44+
- path: /dev/sda
45+
rate: 100
46+
device_write_iops:
47+
- path: /dev/sda
48+
rate: 200
49+
`)
50+
expect := func(p *types.Project) {
51+
bc := p.Services["foo"].BlkioConfig
52+
assert.Equal(t, bc.Weight, uint16(300))
53+
assert.Equal(t, bc.WeightDevice[0].Path, "/dev/sda")
54+
assert.Equal(t, bc.WeightDevice[0].Weight, uint16(400))
55+
assert.Equal(t, bc.DeviceReadBps[0].Path, "/dev/sda")
56+
assert.Equal(t, bc.DeviceReadBps[0].Rate, types.UnitBytes(1024*1024))
57+
assert.Equal(t, bc.DeviceWriteBps[0].Rate, types.UnitBytes(1024))
58+
assert.Equal(t, bc.DeviceReadIOps[0].Rate, types.UnitBytes(100))
59+
assert.Equal(t, bc.DeviceWriteIOps[0].Rate, types.UnitBytes(200))
60+
}
61+
expect(p)
62+
63+
yamlP, jsonP := roundTrip(t, p)
64+
expect(yamlP)
65+
expect(jsonP)
66+
}

loader/tests/build_extra_test.go

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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 tests
18+
19+
import (
20+
"testing"
21+
22+
"github.com/compose-spec/compose-go/v2/types"
23+
"gotest.tools/v3/assert"
24+
)
25+
26+
func TestBuildCacheTo(t *testing.T) {
27+
p := load(t, `
28+
name: test
29+
services:
30+
foo:
31+
build:
32+
context: .
33+
cache_to:
34+
- user/app:cache
35+
- type=local,dest=path/to/cache
36+
`)
37+
38+
expect := func(p *types.Project) {
39+
assert.DeepEqual(t, p.Services["foo"].Build.CacheTo, types.StringList{"user/app:cache", "type=local,dest=path/to/cache"})
40+
}
41+
expect(p)
42+
43+
yamlP, jsonP := roundTrip(t, p)
44+
expect(yamlP)
45+
expect(jsonP)
46+
}
47+
48+
func TestBuildNoCache(t *testing.T) {
49+
p := load(t, `
50+
name: test
51+
services:
52+
foo:
53+
build:
54+
context: .
55+
no_cache: true
56+
`)
57+
58+
expect := func(p *types.Project) {
59+
assert.Equal(t, p.Services["foo"].Build.NoCache, true)
60+
}
61+
expect(p)
62+
63+
yamlP, jsonP := roundTrip(t, p)
64+
expect(yamlP)
65+
expect(jsonP)
66+
}
67+
68+
func TestBuildPull(t *testing.T) {
69+
p := load(t, `
70+
name: test
71+
services:
72+
foo:
73+
build:
74+
context: .
75+
pull: true
76+
`)
77+
78+
expect := func(p *types.Project) {
79+
assert.Equal(t, p.Services["foo"].Build.Pull, true)
80+
}
81+
expect(p)
82+
83+
yamlP, jsonP := roundTrip(t, p)
84+
expect(yamlP)
85+
expect(jsonP)
86+
}
87+
88+
func TestBuildShmSize(t *testing.T) {
89+
p := load(t, `
90+
name: test
91+
services:
92+
foo:
93+
build:
94+
context: .
95+
shm_size: 128m
96+
`)
97+
98+
expect := func(p *types.Project) {
99+
assert.Equal(t, p.Services["foo"].Build.ShmSize, types.UnitBytes(128*1024*1024))
100+
}
101+
expect(p)
102+
103+
yamlP, jsonP := roundTrip(t, p)
104+
expect(yamlP)
105+
expect(jsonP)
106+
}
107+
108+
func TestBuildIsolation(t *testing.T) {
109+
p := load(t, `
110+
name: test
111+
services:
112+
foo:
113+
build:
114+
context: .
115+
isolation: process
116+
`)
117+
118+
expect := func(p *types.Project) {
119+
assert.Equal(t, p.Services["foo"].Build.Isolation, "process")
120+
}
121+
expect(p)
122+
123+
yamlP, jsonP := roundTrip(t, p)
124+
expect(yamlP)
125+
expect(jsonP)
126+
}
127+
128+
func TestBuildPrivileged(t *testing.T) {
129+
p := load(t, `
130+
name: test
131+
services:
132+
foo:
133+
build:
134+
context: .
135+
privileged: true
136+
`)
137+
138+
expect := func(p *types.Project) {
139+
assert.Equal(t, p.Services["foo"].Build.Privileged, true)
140+
}
141+
expect(p)
142+
143+
yamlP, jsonP := roundTrip(t, p)
144+
expect(yamlP)
145+
expect(jsonP)
146+
}

0 commit comments

Comments
 (0)