|
|
@@ -6,6 +6,7 @@ import (
|
|
|
"log"
|
|
|
"net/url"
|
|
|
"strings"
|
|
|
+ "testing"
|
|
|
|
|
|
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
|
|
"github.com/Azure/go-autorest/autorest/to"
|
|
|
@@ -14,6 +15,7 @@ import (
|
|
|
"github.com/Azure/azure-storage-file-go/azfile"
|
|
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
+ "github.com/stretchr/testify/suite"
|
|
|
|
|
|
"github.com/docker/api/azure"
|
|
|
"github.com/docker/api/context/store"
|
|
|
@@ -29,51 +31,60 @@ const (
|
|
|
testContainerName = "testcontainername"
|
|
|
)
|
|
|
|
|
|
-func main() {
|
|
|
- SetupTest()
|
|
|
+var (
|
|
|
+ subscriptionID string
|
|
|
+)
|
|
|
+
|
|
|
+type E2eACISuite struct {
|
|
|
+ Suite
|
|
|
+}
|
|
|
|
|
|
+func (s *E2eACISuite) TestContextHelp() {
|
|
|
It("ensures context command includes azure-login and aci-create", func() {
|
|
|
- output := NewDockerCommand("context", "create", "--help").ExecOrDie()
|
|
|
+ output := s.NewDockerCommand("context", "create", "--help").ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring("docker context create CONTEXT BACKEND [OPTIONS] [flags]"))
|
|
|
Expect(output).To(ContainSubstring("--aci-location"))
|
|
|
Expect(output).To(ContainSubstring("--aci-subscription-id"))
|
|
|
Expect(output).To(ContainSubstring("--aci-resource-group"))
|
|
|
})
|
|
|
+}
|
|
|
|
|
|
+func (s *E2eACISuite) TestContextDefault() {
|
|
|
It("should be initialized with default context", func() {
|
|
|
- _, err := NewCommand("docker", "context", "rm", "-f", contextName).Exec()
|
|
|
+ _, err := s.NewCommand("docker", "context", "rm", "-f", contextName).Exec()
|
|
|
if err == nil {
|
|
|
log.Println("Cleaning existing test context")
|
|
|
}
|
|
|
|
|
|
- NewCommand("docker", "context", "use", "default").ExecOrDie()
|
|
|
- output := NewCommand("docker", "context", "ls").ExecOrDie()
|
|
|
+ s.NewCommand("docker", "context", "use", "default").ExecOrDie()
|
|
|
+ output := s.NewCommand("docker", "context", "ls").ExecOrDie()
|
|
|
Expect(output).To(Not(ContainSubstring(contextName)))
|
|
|
Expect(output).To(ContainSubstring("default *"))
|
|
|
})
|
|
|
+}
|
|
|
|
|
|
- var subscriptionID string
|
|
|
+func (s *E2eACISuite) TestACIBackend() {
|
|
|
It("creates a new aci context for tests", func() {
|
|
|
setupTestResourceGroup(resourceGroupName)
|
|
|
var err error
|
|
|
subscriptionID, err = azure.GetSubscriptionID(context.TODO())
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
|
- NewDockerCommand("context", "create", contextName, "aci", "--aci-subscription-id", subscriptionID, "--aci-resource-group", resourceGroupName, "--aci-location", location).ExecOrDie()
|
|
|
+ s.NewDockerCommand("context", "create", contextName, "aci", "--aci-subscription-id", subscriptionID, "--aci-resource-group", resourceGroupName, "--aci-location", location).ExecOrDie()
|
|
|
// Expect(output).To(ContainSubstring("ACI context acitest created"))
|
|
|
})
|
|
|
|
|
|
defer deleteResourceGroup(resourceGroupName)
|
|
|
|
|
|
It("uses the aci context", func() {
|
|
|
- currentContext := NewCommand("docker", "context", "use", contextName).ExecOrDie()
|
|
|
+ currentContext := s.NewCommand("docker", "context", "use", contextName).ExecOrDie()
|
|
|
Expect(currentContext).To(ContainSubstring(contextName))
|
|
|
- output := NewCommand("docker", "context", "ls").ExecOrDie()
|
|
|
+ output := s.NewCommand("docker", "context", "ls").ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring("acitest *"))
|
|
|
})
|
|
|
|
|
|
It("ensures no container is running initially", func() {
|
|
|
- output := NewDockerCommand("ps").ExecOrDie()
|
|
|
+ output := s.NewDockerCommand("ps").ExecOrDie()
|
|
|
Expect(len(Lines(output))).To(Equal(1))
|
|
|
})
|
|
|
|
|
|
@@ -91,13 +102,13 @@ func main() {
|
|
|
uploadFile(credential, u.String(), testFileName, testFileContent)
|
|
|
|
|
|
mountTarget := "/usr/share/nginx/html"
|
|
|
- output := NewDockerCommand("run", "nginx",
|
|
|
+ output := s.NewDockerCommand("run", "nginx",
|
|
|
"-v", fmt.Sprintf("%s:%s@%s:%s",
|
|
|
testStorageAccountName, firstKey, testShareName, mountTarget),
|
|
|
"-p", "80:80",
|
|
|
"--name", testContainerName).ExecOrDie()
|
|
|
Expect(output).To(Equal(testContainerName + "\n"))
|
|
|
- output = NewDockerCommand("ps").ExecOrDie()
|
|
|
+ output = s.NewDockerCommand("ps").ExecOrDie()
|
|
|
lines := Lines(output)
|
|
|
Expect(len(lines)).To(Equal(2))
|
|
|
|
|
|
@@ -108,19 +119,19 @@ func main() {
|
|
|
Expect(exposedIP).To(ContainSubstring(":80->80/tcp"))
|
|
|
|
|
|
publishedURL := strings.ReplaceAll(exposedIP, "->80/tcp", "")
|
|
|
- output = NewCommand("curl", publishedURL).ExecOrDie()
|
|
|
+ output = s.NewCommand("curl", publishedURL).ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring(testFileContent))
|
|
|
})
|
|
|
|
|
|
It("removes container nginx", func() {
|
|
|
- output := NewDockerCommand("rm", testContainerName).ExecOrDie()
|
|
|
+ output := s.NewDockerCommand("rm", testContainerName).ExecOrDie()
|
|
|
Expect(Lines(output)[0]).To(Equal(testContainerName))
|
|
|
})
|
|
|
|
|
|
It("deploys a compose app", func() {
|
|
|
- NewDockerCommand("compose", "up", "-f", "./tests/composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie()
|
|
|
+ s.NewDockerCommand("compose", "up", "-f", "../composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie()
|
|
|
// Expect(output).To(ContainSubstring("Successfully deployed"))
|
|
|
- output := NewDockerCommand("ps").ExecOrDie()
|
|
|
+ output := s.NewDockerCommand("ps").ExecOrDie()
|
|
|
Lines := Lines(output)
|
|
|
Expect(len(Lines)).To(Equal(4))
|
|
|
webChecked := false
|
|
|
@@ -134,9 +145,9 @@ func main() {
|
|
|
Expect(exposedIP).To(ContainSubstring(":80->80/tcp"))
|
|
|
|
|
|
url := strings.ReplaceAll(exposedIP, "->80/tcp", "")
|
|
|
- output = NewCommand("curl", url).ExecOrDie()
|
|
|
+ output = s.NewCommand("curl", url).ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring("Docker Compose demo"))
|
|
|
- output = NewCommand("curl", url+"/words/noun").ExecOrDie()
|
|
|
+ output = s.NewCommand("curl", url+"/words/noun").ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring("\"word\":"))
|
|
|
}
|
|
|
}
|
|
|
@@ -145,20 +156,20 @@ func main() {
|
|
|
})
|
|
|
|
|
|
It("get logs from web service", func() {
|
|
|
- output := NewDockerCommand("logs", "acidemo_web").ExecOrDie()
|
|
|
+ output := s.NewDockerCommand("logs", "acidemo_web").ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring("Listening on port 80"))
|
|
|
})
|
|
|
|
|
|
It("shutdown compose app", func() {
|
|
|
- NewDockerCommand("compose", "down", "-f", "./tests/composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie()
|
|
|
+ s.NewDockerCommand("compose", "down", "-f", "../composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie()
|
|
|
})
|
|
|
It("switches back to default context", func() {
|
|
|
- output := NewCommand("docker", "context", "use", "default").ExecOrDie()
|
|
|
+ output := s.NewCommand("docker", "context", "use", "default").ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring("default"))
|
|
|
})
|
|
|
|
|
|
It("deletes test context", func() {
|
|
|
- output := NewCommand("docker", "context", "rm", contextName).ExecOrDie()
|
|
|
+ output := s.NewCommand("docker", "context", "rm", contextName).ExecOrDie()
|
|
|
Expect(output).To(ContainSubstring(contextName))
|
|
|
})
|
|
|
}
|
|
|
@@ -212,6 +223,10 @@ func uploadFile(credential azfile.SharedKeyCredential, baseURL, fileName, fileCo
|
|
|
Expect(err).To(BeNil())
|
|
|
}
|
|
|
|
|
|
+func TestE2eACI(t *testing.T) {
|
|
|
+ suite.Run(t, new(E2eACISuite))
|
|
|
+}
|
|
|
+
|
|
|
func setupTestResourceGroup(groupName string) {
|
|
|
log.Println("Creating resource group " + resourceGroupName)
|
|
|
ctx := context.TODO()
|