mirror of
https://github.com/docker/compose.git
synced 2025-07-25 14:44:29 +02:00
Tests on compose conversion
This commit is contained in:
parent
4398560a40
commit
25d912c1ed
@ -3,14 +3,9 @@ package azure
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance"
|
|
||||||
"github.com/Azure/go-autorest/autorest/to"
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/docker/api/azure/convert"
|
|
||||||
"github.com/docker/api/containers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackendSuiteTest struct {
|
type BackendSuiteTest struct {
|
||||||
@ -35,56 +30,3 @@ func TestBackendSuite(t *testing.T) {
|
|||||||
RegisterTestingT(t)
|
RegisterTestingT(t)
|
||||||
suite.Run(t, new(BackendSuiteTest))
|
suite.Run(t, new(BackendSuiteTest))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerGroupToContainer(t *testing.T) {
|
|
||||||
myContainerGroup := containerinstance.ContainerGroup{
|
|
||||||
ContainerGroupProperties: &containerinstance.ContainerGroupProperties{
|
|
||||||
IPAddress: &containerinstance.IPAddress{
|
|
||||||
Ports: &[]containerinstance.Port{{
|
|
||||||
Port: to.Int32Ptr(80),
|
|
||||||
}},
|
|
||||||
IP: to.StringPtr("42.42.42.42"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
myContainer := containerinstance.Container{
|
|
||||||
Name: to.StringPtr("myContainerID"),
|
|
||||||
ContainerProperties: &containerinstance.ContainerProperties{
|
|
||||||
Image: to.StringPtr("sha256:666"),
|
|
||||||
Command: to.StringSlicePtr([]string{"mycommand"}),
|
|
||||||
Ports: &[]containerinstance.ContainerPort{{
|
|
||||||
Port: to.Int32Ptr(80),
|
|
||||||
}},
|
|
||||||
EnvironmentVariables: nil,
|
|
||||||
InstanceView: &containerinstance.ContainerPropertiesInstanceView{
|
|
||||||
RestartCount: nil,
|
|
||||||
CurrentState: &containerinstance.ContainerState{
|
|
||||||
State: to.StringPtr("Running"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Resources: &containerinstance.ResourceRequirements{
|
|
||||||
Limits: &containerinstance.ResourceLimits{
|
|
||||||
MemoryInGB: to.Float64Ptr(9),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var expectedContainer = containers.Container{
|
|
||||||
ID: "myContainerID",
|
|
||||||
Status: "Running",
|
|
||||||
Image: "sha256:666",
|
|
||||||
Command: "mycommand",
|
|
||||||
MemoryLimit: 9,
|
|
||||||
Ports: []containers.Port{{
|
|
||||||
HostPort: uint32(80),
|
|
||||||
ContainerPort: uint32(80),
|
|
||||||
Protocol: "tcp",
|
|
||||||
HostIP: "42.42.42.42",
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
|
|
||||||
container, err := convert.ContainerGroupToContainer("myContainerID", myContainerGroup, myContainer)
|
|
||||||
Expect(err).To(BeNil())
|
|
||||||
Expect(container).To(Equal(expectedContainer))
|
|
||||||
}
|
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
// ComposeDNSSidecarName name of the dns sidecar container
|
// ComposeDNSSidecarName name of the dns sidecar container
|
||||||
ComposeDNSSidecarName = "aci--dns--sidecar"
|
ComposeDNSSidecarName = "aci--dns--sidecar"
|
||||||
|
dnsSidecarImage = "alpine:3.12.0"
|
||||||
|
|
||||||
azureFileDriverName = "azure_file"
|
azureFileDriverName = "azure_file"
|
||||||
volumeDriveroptsShareNameKey = "share_name"
|
volumeDriveroptsShareNameKey = "share_name"
|
||||||
@ -118,7 +119,7 @@ func getDNSSidecar(containers []containerinstance.Container) containerinstance.C
|
|||||||
dnsSideCar := containerinstance.Container{
|
dnsSideCar := containerinstance.Container{
|
||||||
Name: to.StringPtr(ComposeDNSSidecarName),
|
Name: to.StringPtr(ComposeDNSSidecarName),
|
||||||
ContainerProperties: &containerinstance.ContainerProperties{
|
ContainerProperties: &containerinstance.ContainerProperties{
|
||||||
Image: to.StringPtr("alpine:3.12.0"),
|
Image: to.StringPtr(dnsSidecarImage),
|
||||||
Command: &alpineCmd,
|
Command: &alpineCmd,
|
||||||
Resources: &containerinstance.ResourceRequirements{
|
Resources: &containerinstance.ResourceRequirements{
|
||||||
Limits: &containerinstance.ResourceLimits{
|
Limits: &containerinstance.ResourceLimits{
|
||||||
|
@ -3,44 +3,148 @@ package convert
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance"
|
||||||
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
|
||||||
"github.com/docker/api/compose"
|
"github.com/docker/api/compose"
|
||||||
|
"github.com/docker/api/containers"
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
|
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
projectName = "TEST"
|
|
||||||
expectedProjectName = "test"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ConvertTestSuite struct {
|
type ConvertTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
ctx store.AciContext
|
ctx store.AciContext
|
||||||
project compose.Project
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConvertTestSuite) BeforeTest(suiteName, testName string) {
|
func (suite *ConvertTestSuite) BeforeTest(suiteName, testName string) {
|
||||||
ctx := store.AciContext{
|
suite.ctx = store.AciContext{
|
||||||
SubscriptionID: "subID",
|
SubscriptionID: "subID",
|
||||||
ResourceGroup: "rg",
|
ResourceGroup: "rg",
|
||||||
Location: "eu",
|
Location: "eu",
|
||||||
}
|
}
|
||||||
project := compose.Project{
|
|
||||||
Name: projectName,
|
|
||||||
}
|
|
||||||
|
|
||||||
suite.ctx = ctx
|
|
||||||
suite.project = project
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConvertTestSuite) TestProjectName() {
|
func (suite *ConvertTestSuite) TestProjectName() {
|
||||||
containerGroup, err := ToContainerGroup(suite.ctx, suite.project)
|
project := compose.Project{
|
||||||
|
Name: "TEST",
|
||||||
|
}
|
||||||
|
containerGroup, err := ToContainerGroup(suite.ctx, project)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
require.Equal(suite.T(), *containerGroup.Name, expectedProjectName)
|
require.Equal(suite.T(), *containerGroup.Name, "test")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ConvertTestSuite) TestContainerGroupToContainer() {
|
||||||
|
myContainerGroup := containerinstance.ContainerGroup{
|
||||||
|
ContainerGroupProperties: &containerinstance.ContainerGroupProperties{
|
||||||
|
IPAddress: &containerinstance.IPAddress{
|
||||||
|
Ports: &[]containerinstance.Port{{
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
}},
|
||||||
|
IP: to.StringPtr("42.42.42.42"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
myContainer := containerinstance.Container{
|
||||||
|
Name: to.StringPtr("myContainerID"),
|
||||||
|
ContainerProperties: &containerinstance.ContainerProperties{
|
||||||
|
Image: to.StringPtr("sha256:666"),
|
||||||
|
Command: to.StringSlicePtr([]string{"mycommand"}),
|
||||||
|
Ports: &[]containerinstance.ContainerPort{{
|
||||||
|
Port: to.Int32Ptr(80),
|
||||||
|
}},
|
||||||
|
EnvironmentVariables: nil,
|
||||||
|
InstanceView: &containerinstance.ContainerPropertiesInstanceView{
|
||||||
|
RestartCount: nil,
|
||||||
|
CurrentState: &containerinstance.ContainerState{
|
||||||
|
State: to.StringPtr("Running"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Resources: &containerinstance.ResourceRequirements{
|
||||||
|
Limits: &containerinstance.ResourceLimits{
|
||||||
|
MemoryInGB: to.Float64Ptr(9),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var expectedContainer = containers.Container{
|
||||||
|
ID: "myContainerID",
|
||||||
|
Status: "Running",
|
||||||
|
Image: "sha256:666",
|
||||||
|
Command: "mycommand",
|
||||||
|
MemoryLimit: 9,
|
||||||
|
Ports: []containers.Port{{
|
||||||
|
HostPort: uint32(80),
|
||||||
|
ContainerPort: uint32(80),
|
||||||
|
Protocol: "tcp",
|
||||||
|
HostIP: "42.42.42.42",
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
|
||||||
|
container, err := ContainerGroupToContainer("myContainerID", myContainerGroup, myContainer)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(container).To(Equal(expectedContainer))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ConvertTestSuite) TestComposeContainerGroupToContainerWithDnsSideCarSide() {
|
||||||
|
project := compose.Project{
|
||||||
|
Name: "",
|
||||||
|
Config: types.Config{
|
||||||
|
Services: []types.ServiceConfig{
|
||||||
|
{
|
||||||
|
Name: "service1",
|
||||||
|
Image: "image1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "service2",
|
||||||
|
Image: "image2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
group, err := ToContainerGroup(suite.ctx, project)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(len(*group.Containers)).To(Equal(3))
|
||||||
|
|
||||||
|
Expect(*(*group.Containers)[0].Name).To(Equal("service1"))
|
||||||
|
Expect(*(*group.Containers)[1].Name).To(Equal("service2"))
|
||||||
|
Expect(*(*group.Containers)[2].Name).To(Equal(ComposeDNSSidecarName))
|
||||||
|
|
||||||
|
Expect(*(*group.Containers)[2].Command).To(Equal([]string{"sh", "-c", "echo 127.0.0.1 service1 >> /etc/hosts;echo 127.0.0.1 service2 >> /etc/hosts;sleep infinity"}))
|
||||||
|
|
||||||
|
Expect(*(*group.Containers)[0].Image).To(Equal("image1"))
|
||||||
|
Expect(*(*group.Containers)[1].Image).To(Equal("image2"))
|
||||||
|
Expect(*(*group.Containers)[2].Image).To(Equal(dnsSidecarImage))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ConvertTestSuite) TestComposeSingleContainerGroupToContainerNoDnsSideCarSide() {
|
||||||
|
project := compose.Project{
|
||||||
|
Name: "",
|
||||||
|
Config: types.Config{
|
||||||
|
Services: []types.ServiceConfig{
|
||||||
|
{
|
||||||
|
Name: "service1",
|
||||||
|
Image: "image1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
group, err := ToContainerGroup(suite.ctx, project)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
Expect(len(*group.Containers)).To(Equal(1))
|
||||||
|
Expect(*(*group.Containers)[0].Name).To(Equal("service1"))
|
||||||
|
Expect(*(*group.Containers)[0].Image).To(Equal("image1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertTestSuite(t *testing.T) {
|
func TestConvertTestSuite(t *testing.T) {
|
||||||
|
RegisterTestingT(t)
|
||||||
suite.Run(t, new(ConvertTestSuite))
|
suite.Run(t, new(ConvertTestSuite))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user