Add trait attach cases and refactor all others

This commit is contained in:
zzxwill
2020-08-05 00:41:23 +08:00
parent 940a7587d9
commit 90d7d78435
7 changed files with 159 additions and 128 deletions

View File

@@ -1,4 +1,4 @@
e2e/application/application_suite_test.gopackage e2e
package e2e
import (
"testing"

View File

@@ -1,4 +1,4 @@
e2e/application/application_test.go package e2e
package e2e
import (
"fmt"
@@ -15,44 +15,19 @@ var (
)
var _ = ginkgo.Describe("Application", func() {
ginkgo.Context("env init", func() {
ginkgo.It("should print env initiation successful message", func() {
cli := fmt.Sprintf("rudr env:init %s --namespace %s", envName, envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Create env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("env sw", func() {
ginkgo.It("should show env switch message", func() {
cli := fmt.Sprintf("rudr env:sw %s", envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Switch env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("run", func() {
ginkgo.It("should print successful creation information", func() {
cli := fmt.Sprintf("rudr containerized:run %s -p 80 --image nginx:1.9.4", applicationName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("SUCCEED"))
})
})
e2e.EnvInitContext("env init", envName)
e2e.EnvShowContext("env show", envName)
e2e.EnvSwitchContext("env switch", envName)
e2e.WorkloadRunContext("run", fmt.Sprintf("rudr containerized:run %s -p 80 --image nginx:1.9.4", applicationName))
ginkgo.Context("ls", func() {
ginkgo.It("should list all applications", func() {
output, err := e2e.Exec("rudr ls")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("NAME \tWORKLOAD \tTRAITS \tSTATUS\tCREATED-TIME"))
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
gomega.Expect(output).To(gomega.ContainSubstring(applicationName))
})
})
e2e.WorkloadDeleteContext(applicationName)
e2e.WorkloadDeleteContext("delete", applicationName)
})

View File

@@ -8,8 +8,80 @@ import (
)
var (
WorkloadDeleteContext = func(applicationName string) bool {
return ginkgo.Context("delete", func() {
// Env
EnvInitContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should print env initiation successful message", func() {
cli := fmt.Sprintf("rudr env:init %s --namespace %s", envName, envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Create env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
}
EnvShowContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should show detailed env message", func() {
cli := fmt.Sprintf("rudr env %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("%s\t%s", envName, envName)
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
gomega.Expect(output).To(gomega.ContainSubstring("NAMESPACE"))
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
}
EnvSwitchContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should show env switch message", func() {
cli := fmt.Sprintf("rudr env:sw %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Switch env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
}
EnvDeleteContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should delete all envs", func() {
cli := fmt.Sprintf("rudr env:delete %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("%s deleted", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
}
EnvDeleteCurrentUsingContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should delete all envs", func() {
cli := fmt.Sprintf("rudr env:delete %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Error: you can't delete current using env %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
}
//Workload
WorkloadRunContext = func(context string, cli string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should print successful creation information", func() {
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("SUCCEED"))
})
})
}
WorkloadDeleteContext = func(context string, applicationName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should print successful deletion information", func() {
cli := fmt.Sprintf("rudr delete %s", applicationName)
output, err := Exec(cli)

68
e2e/env/env_test.go vendored
View File

@@ -1,8 +1,6 @@
package e2e
import (
"fmt"
"github.com/cloud-native-application/rudrx/e2e"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
@@ -14,47 +12,10 @@ var (
)
var _ = ginkgo.Describe("Env", func() {
ginkgo.Context("env init", func() {
ginkgo.It("should print env initiation successful message", func() {
cli := fmt.Sprintf("rudr env:init %s --namespace %s", envName, envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Create env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("env init another one", func() {
ginkgo.It("should print env initiation successful message", func() {
cli := fmt.Sprintf("rudr env:init %s --namespace %s", envName2, envName2)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Create env succeed, current env is %s", envName2)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("env show", func() {
ginkgo.It("should show detailed env message", func() {
cli := fmt.Sprintf("rudr env %s", envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("%s\t%s", envName, envName)
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
gomega.Expect(output).To(gomega.ContainSubstring("NAMESPACE"))
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("env sw", func() {
ginkgo.It("should show env switch message", func() {
cli := fmt.Sprintf("rudr env:sw %s", envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Switch env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
e2e.EnvInitContext("env init", envName)
e2e.EnvInitContext("env init another one", envName2)
e2e.EnvShowContext("env show", envName)
e2e.EnvSwitchContext("env sw", envName)
ginkgo.Context("env list", func() {
ginkgo.It("should list all envs", func() {
@@ -67,23 +28,6 @@ var _ = ginkgo.Describe("Env", func() {
})
})
ginkgo.Context("env delete", func() {
ginkgo.It("should delete all envs", func() {
cli := fmt.Sprintf("rudr env:delete %s", envName2)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("%s deleted", envName2)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("env delete currently using one", func() {
ginkgo.It("should delete all envs", func() {
cli := fmt.Sprintf("rudr env:delete %s", envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Error: you can't delete current using env %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
e2e.EnvDeleteContext("env delete", envName2)
e2e.EnvDeleteCurrentUsingContext("env delete currently using one", envName)
})

View File

@@ -0,0 +1,23 @@
package e2e
import (
"testing"
"github.com/cloud-native-application/rudrx/e2e"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)
var rudrPath string
var _ = ginkgo.BeforeSuite(func() {
p, err := e2e.GetCliBinary()
rudrPath = p
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
func TestEnv(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Trait Suite")
}

44
e2e/trait/trait_test.go Normal file
View File

@@ -0,0 +1,44 @@
package e2e
import (
"fmt"
"github.com/onsi/gomega"
"github.com/cloud-native-application/rudrx/e2e"
"github.com/onsi/ginkgo"
)
var (
//TODO(zzxwill) Need to change env name after [issue#82](https://github.com/cloud-native-application/RudrX/issues/82) is fixed.
envName = "default"
applicationName = "app-trait-basic"
)
var _ = ginkgo.Describe("Env", func() {
e2e.EnvInitContext("env init", envName)
e2e.EnvSwitchContext("env switch", envName)
e2e.WorkloadRunContext("run", fmt.Sprintf("rudr containerized:run %s -p 80 --image nginx:1.9.4", applicationName))
ginkgo.Context("rudr attach trait", func() {
ginkgo.It("should print successful attached information", func() {
cli := fmt.Sprintf("rudr ManualScaler %s --replicaCount 4", applicationName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("Applying trait for app"))
gomega.Expect(output).To(gomega.ContainSubstring("Succeeded"))
})
})
//ginkgo.Context("rudr detach trait", func() {
// ginkgo.It("should print successful detached information", func() {
// cli := fmt.Sprintf("rudr ManualScaler %s --detach", applicationName)
// output, err := e2e.Exec(cli)
// gomega.Expect(err).NotTo(gomega.HaveOccurred())
// gomega.Expect(output).To(gomega.ContainSubstring("Applying trait for app"))
// gomega.Expect(output).To(gomega.ContainSubstring("Succeeded"))
// })
//})
e2e.WorkloadDeleteContext("delete", applicationName)
})

View File

@@ -5,7 +5,6 @@ import (
"github.com/cloud-native-application/rudrx/e2e"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)
var (
@@ -15,34 +14,8 @@ var (
)
var _ = ginkgo.Describe("Workload", func() {
ginkgo.Context("env init", func() {
ginkgo.It("should print env initiation successful message", func() {
cli := fmt.Sprintf("rudr env:init %s --namespace %s", envName, envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Create env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("env sw", func() {
ginkgo.It("should show env switch message", func() {
cli := fmt.Sprintf("rudr env:sw %s", envName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Switch env succeed, current env is %s", envName)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput))
})
})
ginkgo.Context("run", func() {
ginkgo.It("should print successful creation information", func() {
cli := fmt.Sprintf("rudr containerized:run %s -p 80 --image nginx:1.9.4", applicationName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("SUCCEED"))
})
})
e2e.WorkloadDeleteContext(applicationName)
e2e.EnvInitContext("env init", envName)
e2e.EnvSwitchContext("env switch", envName)
e2e.WorkloadRunContext("run", fmt.Sprintf("rudr containerized:run %s -p 80 --image nginx:1.9.4", applicationName))
e2e.WorkloadDeleteContext("delete", applicationName)
})