2018-01-31 09:37:14 -05:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
2022-02-25 08:31:31 -05:00
|
|
|
"io"
|
2018-01-31 09:37:14 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
composetypes "github.com/docker/cli/cli/compose/types"
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2018-01-31 09:37:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFromCompose(t *testing.T) {
|
|
|
|
stackClient := &stackV1Beta1{}
|
2022-02-25 08:31:31 -05:00
|
|
|
s, err := stackClient.FromCompose(io.Discard, "foo", &composetypes.Config{
|
2018-01-31 09:37:14 -05:00
|
|
|
Version: "3.1",
|
|
|
|
Filename: "banana",
|
|
|
|
Services: []composetypes.ServiceConfig{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Image: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Image: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NilError(t, err)
|
2018-06-27 10:41:00 -04:00
|
|
|
assert.Equal(t, "foo", s.Name)
|
2018-04-25 09:43:18 -04:00
|
|
|
assert.Equal(t, string(`version: "3.5"
|
2018-01-31 09:37:14 -05:00
|
|
|
services:
|
|
|
|
bar:
|
|
|
|
image: bar
|
|
|
|
foo:
|
|
|
|
image: foo
|
2018-06-27 10:41:00 -04:00
|
|
|
`), s.ComposeFile)
|
2018-01-31 09:37:14 -05:00
|
|
|
}
|
2018-04-25 09:43:18 -04:00
|
|
|
|
|
|
|
func TestFromComposeUnsupportedVersion(t *testing.T) {
|
|
|
|
stackClient := &stackV1Beta1{}
|
2022-02-25 08:31:31 -05:00
|
|
|
_, err := stackClient.FromCompose(io.Discard, "foo", &composetypes.Config{
|
2018-04-25 09:43:18 -04:00
|
|
|
Version: "3.6",
|
|
|
|
Filename: "banana",
|
|
|
|
Services: []composetypes.ServiceConfig{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Image: "foo",
|
|
|
|
Volumes: []composetypes.ServiceVolumeConfig{
|
|
|
|
{
|
|
|
|
Type: "tmpfs",
|
|
|
|
Target: "/app",
|
|
|
|
Tmpfs: &composetypes.ServiceVolumeTmpfs{
|
|
|
|
Size: 10000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.ErrorContains(t, err, "the compose yaml file is invalid with v3.5: services.foo.volumes.0 Additional property tmpfs is not allowed")
|
|
|
|
}
|