Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
461 changes: 0 additions & 461 deletions loader/full-example.yml

This file was deleted.

1,742 changes: 0 additions & 1,742 deletions loader/full-struct_test.go

This file was deleted.

765 changes: 0 additions & 765 deletions loader/loader_test.go

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions loader/tests/annotations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2020 The Compose Specification Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"testing"

"github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert"
)

func TestAnnotations(t *testing.T) {
p := load(t, `
name: test
services:
list:
image: alpine
annotations:
- com.example.foo=bar
map:
image: alpine
annotations:
com.example.foo: bar
`)
expect := func(p *types.Project) {
expected := types.Mapping{"com.example.foo": "bar"}
assert.DeepEqual(t, p.Services["list"].Annotations, expected)
assert.DeepEqual(t, p.Services["map"].Annotations, expected)
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}
50 changes: 50 additions & 0 deletions loader/tests/attach_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2020 The Compose Specification Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"testing"

"github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert"
)

func TestAttach(t *testing.T) {
p := load(t, `
name: test
services:
attached:
image: alpine
attach: true
detached:
image: alpine
attach: false
default:
image: alpine
`)

expect := func(p *types.Project) {
assert.Equal(t, *p.Services["attached"].Attach, true)
assert.Equal(t, *p.Services["detached"].Attach, false)
assert.Assert(t, p.Services["default"].Attach == nil)
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}
66 changes: 66 additions & 0 deletions loader/tests/blkio_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2020 The Compose Specification Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"testing"

"github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert"
)

func TestBlkioConfig(t *testing.T) {
p := load(t, `
name: test
services:
foo:
image: busybox
blkio_config:
weight: 300
weight_device:
- path: /dev/sda
weight: 400
device_read_bps:
- path: /dev/sda
rate: 1024k
device_write_bps:
- path: /dev/sda
rate: 1024
device_read_iops:
- path: /dev/sda
rate: 100
device_write_iops:
- path: /dev/sda
rate: 200
`)
expect := func(p *types.Project) {
bc := p.Services["foo"].BlkioConfig
assert.Equal(t, bc.Weight, uint16(300))
assert.Equal(t, bc.WeightDevice[0].Path, "/dev/sda")
assert.Equal(t, bc.WeightDevice[0].Weight, uint16(400))
assert.Equal(t, bc.DeviceReadBps[0].Path, "/dev/sda")
assert.Equal(t, bc.DeviceReadBps[0].Rate, types.UnitBytes(1024*1024))
assert.Equal(t, bc.DeviceWriteBps[0].Rate, types.UnitBytes(1024))
assert.Equal(t, bc.DeviceReadIOps[0].Rate, types.UnitBytes(100))
assert.Equal(t, bc.DeviceWriteIOps[0].Rate, types.UnitBytes(200))
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}
146 changes: 146 additions & 0 deletions loader/tests/build_extra_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
Copyright 2020 The Compose Specification Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"testing"

"github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert"
)

func TestBuildCacheTo(t *testing.T) {
p := load(t, `
name: test
services:
foo:
build:
context: .
cache_to:
- user/app:cache
- type=local,dest=path/to/cache
`)

expect := func(p *types.Project) {
assert.DeepEqual(t, p.Services["foo"].Build.CacheTo, types.StringList{"user/app:cache", "type=local,dest=path/to/cache"})
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}

func TestBuildNoCache(t *testing.T) {
p := load(t, `
name: test
services:
foo:
build:
context: .
no_cache: true
`)

expect := func(p *types.Project) {
assert.Equal(t, p.Services["foo"].Build.NoCache, true)
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}

func TestBuildPull(t *testing.T) {
p := load(t, `
name: test
services:
foo:
build:
context: .
pull: true
`)

expect := func(p *types.Project) {
assert.Equal(t, p.Services["foo"].Build.Pull, true)
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}

func TestBuildShmSize(t *testing.T) {
p := load(t, `
name: test
services:
foo:
build:
context: .
shm_size: 128m
`)

expect := func(p *types.Project) {
assert.Equal(t, p.Services["foo"].Build.ShmSize, types.UnitBytes(128*1024*1024))
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}

func TestBuildIsolation(t *testing.T) {
p := load(t, `
name: test
services:
foo:
build:
context: .
isolation: process
`)

expect := func(p *types.Project) {
assert.Equal(t, p.Services["foo"].Build.Isolation, "process")
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}

func TestBuildPrivileged(t *testing.T) {
p := load(t, `
name: test
services:
foo:
build:
context: .
privileged: true
`)

expect := func(p *types.Project) {
assert.Equal(t, p.Services["foo"].Build.Privileged, true)
}
expect(p)

yamlP, jsonP := roundTrip(t, p)
expect(yamlP)
expect(jsonP)
}
Loading