github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/docker/service_test.go (about) 1 package docker 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "gopkg.in/yaml.v2" 8 ) 9 10 func TestDockerComposeService(t *testing.T) { 11 tt := assert.New(t) 12 13 serviceString := []byte(` 14 image: nginx:alpine 15 labels: 16 base_path: /kubemgr 17 environment: 18 GOENV: ${GOENV} 19 S_LOG_LEVEL: ${S_LOG_LEVEL} 20 S_MASTERDB_PASSWORD: ${S_MASTERDB_PASSWORD} 21 S_MASTERDB_USER: ${S_MASTERDB_USER} 22 entrypoint: 23 - sh 24 command: 25 - "-c" 26 - "sleep 50000" 27 ports: 28 - 99:80/tcp 29 volumes: 30 - /tmp:/tmp 31 volumes_from: 32 - content:ro 33 `) 34 35 service := Service{} 36 37 err := yaml.Unmarshal(serviceString, &service) 38 tt.Nil(err) 39 40 tt.Equal(Image{ 41 Name: "nginx", 42 Version: "alpine", 43 }, service.Image) 44 45 tt.Equal([]string{"sh"}, service.EntryPoint.Value()) 46 tt.Equal([]string{"-c", "sleep 50000"}, service.Command.Value()) 47 48 tt.Equal([]Port{ 49 { 50 Port: 99, 51 ContainerPort: 80, 52 Protocol: ProtocolTCP, 53 }, 54 }, service.Ports) 55 56 tt.Equal([]Volume{ 57 { 58 LocalPath: "/tmp", 59 MountPath: "/tmp", 60 AccessMode: VolumeAccessModeReadWrite, 61 }, 62 }, service.Volumes) 63 64 tt.Equal([]Volume{ 65 { 66 Name: "content", 67 AccessMode: VolumeAccessModeReadOnly, 68 }, 69 }, service.VolumesFrom) 70 71 bytes, err := yaml.Marshal(service) 72 tt.Nil(err) 73 74 t.Log(string(bytes)) 75 }