github.com/ali-iotechsys/cli@v20.10.0+incompatible/cli/command/stack/kubernetes/stackclient_test.go (about) 1 package kubernetes 2 3 import ( 4 "io/ioutil" 5 "testing" 6 7 composetypes "github.com/docker/cli/cli/compose/types" 8 "gotest.tools/v3/assert" 9 ) 10 11 func TestFromCompose(t *testing.T) { 12 stackClient := &stackV1Beta1{} 13 s, err := stackClient.FromCompose(ioutil.Discard, "foo", &composetypes.Config{ 14 Version: "3.1", 15 Filename: "banana", 16 Services: []composetypes.ServiceConfig{ 17 { 18 Name: "foo", 19 Image: "foo", 20 }, 21 { 22 Name: "bar", 23 Image: "bar", 24 }, 25 }, 26 }) 27 assert.NilError(t, err) 28 assert.Equal(t, "foo", s.Name) 29 assert.Equal(t, string(`version: "3.5" 30 services: 31 bar: 32 image: bar 33 foo: 34 image: foo 35 `), s.ComposeFile) 36 } 37 38 func TestFromComposeUnsupportedVersion(t *testing.T) { 39 stackClient := &stackV1Beta1{} 40 _, err := stackClient.FromCompose(ioutil.Discard, "foo", &composetypes.Config{ 41 Version: "3.6", 42 Filename: "banana", 43 Services: []composetypes.ServiceConfig{ 44 { 45 Name: "foo", 46 Image: "foo", 47 Volumes: []composetypes.ServiceVolumeConfig{ 48 { 49 Type: "tmpfs", 50 Target: "/app", 51 Tmpfs: &composetypes.ServiceVolumeTmpfs{ 52 Size: 10000, 53 }, 54 }, 55 }, 56 }, 57 }, 58 }) 59 assert.ErrorContains(t, err, "the compose yaml file is invalid with v3.5: services.foo.volumes.0 Additional property tmpfs is not allowed") 60 }