Skip to content

Commit

Permalink
add complete stack life cycle test
Browse files Browse the repository at this point in the history
  • Loading branch information
freignat91 committed Sep 21, 2016
1 parent d8ce8ce commit a1ba3f8
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ test:
@go test $(REPO)/api/rpc/logs
# @go test $(REPO)/api/rpc/project
@go test $(REPO)/api/rpc/service
@go test $(REPO)/data/storage/etcd
@go test $(REPO)/api/rpc/stack
# @go test $(REPO)/api/rpc/stat
@go test $(REPO)/data/influx
@go test $(REPO)/data/storage/etcd
# @go test $(REPO)/api/rpc/stat
116 changes: 97 additions & 19 deletions api/rpc/stack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
elasticsearchDefaultURL = "http://localhost:9200"
kafkaDefaultURL = "localhost:9092"
influxDefaultURL = "http://localhost:8086"
example = `
example1 = `
pinger:
image: appcelerator/pinger
replicas: 2
Expand All @@ -43,6 +43,25 @@ pingerExt2:
protocol: tcp
publish_port: 3001
internal_port: 3000`
example2 = `
pinger:
image: appcelerator/pinger
replicas: 2
pingerExt1:
image: appcelerator/pinger
replicas: 2
public:
- name: www1
protocol: tcp
internal_port: 3000
pingerExt2:
image: appcelerator/pinger
replicas: 2
public:
- name: www2
protocol: tcp
publish_port: 3002
internal_port: 3000`
)

var (
Expand Down Expand Up @@ -106,30 +125,89 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestShouldUpStopRemoveStackSuccessfully(t *testing.T) {
rUp, errUp := client.Up(ctx, &stack.UpRequest{StackName: "essai", Stackfile: example})
if errUp != nil {
t.Fatal(errUp)
//Test two stacks life cycle in the same time
func TestShouldManageStackLifeCycleSuccessfully(t *testing.T) {
//Start stack essai1
t.Log("start stack essai1")
rUp1, errUp1 := client.Up(ctx, &stack.UpRequest{StackName: "essai1", Stackfile: example1})
if errUp1 != nil {
t.Fatal(errUp1)
}
//Start stack essai2
t.Log("start stack essai2")
rUp2, errUp2 := client.Up(ctx, &stack.UpRequest{StackName: "essai2", Stackfile: example2})
if errUp2 != nil {
t.Fatal(errUp2)
}
assert.NotEmpty(t, rUp1.StackId, "Stack essai1 StackId should not be empty")
assert.NotEmpty(t, rUp2.StackId, "Stack essai2 StackId should not be empty")
time.Sleep(5 * time.Second)
//verifyusing ls
t.Log("perform stack ls")
listRequest := stack.ListRequest{}
rls, errls := client.List(ctx, &listRequest)
if errls != nil {
t.Fatal(errls)
}
assert.Equal(t, len(rls.List), 2, "amp stack ls should return two lines")
//Prepare requests
stackRequest1 := stack.StackRequest{
StackIdent: rUp1.StackId,
}
stackRequest2 := stack.StackRequest{
StackIdent: rUp2.StackId,
}
//Stop stack essai1
t.Log("stop stack essai1")
rStop1, errStop1 := client.Stop(ctx, &stackRequest1)
if errStop1 != nil {
t.Fatal(errStop1)
}
assert.NotEmpty(t, rStop1.StackId, "Stack essai1 StackId should not be empty")
//Restart stack essai1
t.Log("restart stack essai1")
rRestart1, errRestart1 := client.Start(ctx, &stackRequest1)
if errRestart1 != nil {
t.Fatal(errRestart1)
}
assert.NotEmpty(t, rRestart1.StackId, "Stack essai1 StackId should not be empty")
time.Sleep(3 * time.Second)
//Stop again stack essai1
t.Log("stop again stack essai1")
rStop12, errStop12 := client.Stop(ctx, &stackRequest1)
if errStop12 != nil {
t.Fatal(errStop12)
}
assert.NotEmpty(t, rStop12.StackId, "Stack essai1 StackId should not be empty")
t.Log("remove stack essai1")
//Remove stack essai1
removeRequest1 := stack.RemoveRequest{
StackIdent: rUp1.StackId,
Force: false,
}
assert.NotEmpty(t, rUp.StackId, "StackId should not be empty")
fmt.Printf("Stack id = %s\n", rUp.StackId)
stackRequest := stack.StackRequest{
StackIdent: rUp.StackId,
rRemove1, errRemove1 := client.Remove(ctx, &removeRequest1)
if errRemove1 != nil {
t.Fatal(errRemove1)
}
rStop, errStop := client.Stop(ctx, &stackRequest)
if errStop != nil {
t.Fatal(errStop)
assert.NotEmpty(t, rRemove1.StackId, "Stack essai1 StackId should not be empty")
//Stop stack essai2
t.Log("stop stack essai2")
rStop2, errStop2 := client.Stop(ctx, &stackRequest2)
if errStop2 != nil {
t.Fatal(errStop2)
}
assert.NotEmpty(t, rStop.StackId, "StackId should not be empty")
removeRequest := stack.RemoveRequest{
StackIdent: rUp.StackId,
assert.NotEmpty(t, rStop2.StackId, "Stack essai2 StackId should not be empty")
//Remove stack essai2
t.Log("remove stack essai2")
removeRequest2 := stack.RemoveRequest{
StackIdent: rUp2.StackId,
Force: false,
}
rRemove, errRemove := client.Remove(ctx, &removeRequest)
if errRemove != nil {
t.Fatal(errRemove)
rRemove2, errRemove2 := client.Remove(ctx, &removeRequest2)
if errRemove2 != nil {
t.Fatal(errRemove2)
}
assert.NotEmpty(t, rRemove.StackId, "StackId should not be empty")
assert.NotEmpty(t, rRemove2.StackId, "Stack essai2 StackId should not be empty")
}

func TestTransitionsFromStopped(t *testing.T) {
Expand Down

0 comments on commit a1ba3f8

Please sign in to comment.