Skip to content

Commit

Permalink
Merge pull request #9 from vitwit/int-tests
Browse files Browse the repository at this point in the history
Integration Tests
  • Loading branch information
anilcse authored Feb 7, 2020
2 parents 96cbcd7 + fc30006 commit 25c5e77
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 8 deletions.
File renamed without changes.
8 changes: 4 additions & 4 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func main() {
return
}

_, err = cli.GetSystemFunctions()
if err != nil {
golog.Error("Error from system functions: ", err)
}
//_, err = cli.GetSystemFunctions()
//if err != nil {
// golog.Error("Error from system functions: ", err)
//}

data := &faas.FunctionDefintion{
Service: "nodeinfo",
Expand Down
142 changes: 142 additions & 0 deletions go_faas_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// +build integration

package go_faas

import (
"github.com/stretchr/testify/assert"
"testing"
)

func (suite *GoFaasTestSuite) TestFunctionsCRUD() {
funcName := "integration_testnodeinfo"

// get functions
suite.T().Run("IntTests/TestFunctionsCRUD/GetSystemFunctions", func(t *testing.T) {
resp, err := suite.cli.GetSystemFunctions()
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
})

// create a func
def := &FunctionDefintion{
Service: funcName,
Network: "func_functions",
Image: "functions/nodeinfo:latest",
EnvProcess: "node main.js",
Constraints: []string{
"node.platform.os == linux",
},
Labels: map[string]string{
"labelkey": "labelval",
},
Annotations: Annotations{
Topics: "awesome-kafka-topic",
Foo: "some",
},
RegistryAuth: "dXNlcjpwYXNzd29yZA==",
Limits: Limits{
Memory: "128M",
CPU: "0.01",
},
Requests: Requests{
Memory: "128M",
CPU: "0.01",
},
ReadOnlyRootFilesystem: true,
}
suite.T().Run("IntTests/TestFunctionsCRUD/CreateSystemFunctions", func(t *testing.T) {
resp, err = suite.cli.CreateSystemFunctions(def)
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})

// get function summary
suite.T().Run("IntTests/TestFunctionsCRUD/GetFunctionSummary", func(t *testing.T) {
resp, err = suite.cli.GetFunctionSummary(funcName)
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
})

// update the func
update := &FunctionDefintion{
Service: funcName,
Image: "functions/nodeinfo:latest",
Limits: Limits{
Memory: "130M",
CPU: "0.01",
},
}
suite.T().Run("IntTests/TestFunctionsCRUD/UpdateSystemFunctions", func(t *testing.T) {
resp, err = suite.cli.UpdateSystemFunctions(update)
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})

// scale up the func
suite.T().Run("IntTests/TestFunctionsCRUD/ScaleFunction/Up", func(t *testing.T) {
resp, err = suite.cli.ScaleFunction(&ScaleFunctionBodyOpts{
Service: funcName,
Replicas: 3,
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})

// scale down the func
suite.T().Run("IntTests/TestFunctionsCRUD/ScaleFunction/Down", func(t *testing.T) {
resp, err = suite.cli.ScaleFunction(&ScaleFunctionBodyOpts{
Service: funcName,
Replicas: 1,
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})

// delete the func
suite.T().Run("IntTests/TestFunctionsCRUD/DeleteSystemFunction", func(t *testing.T) {
resp, err = suite.cli.DeleteSystemFunction(&DeleteFunctionBodyOpts{FunctionName: funcName})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)
})
}

func (suite *GoFaasTestSuite) TestSecretsCRUD() {
secretName := "integration_test_secret"
secretVal := "integration_test_secret_val"

//get secrets list
suite.T().Run("IntTests/TestSecretsCRUD/GetSecrets", func(t *testing.T) {
resp, err := suite.cli.GetSecrets()
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), resp.StatusCode, 200)
})

// create new secret
suite.T().Run("IntTests/TestSecretsCRUD/CreateNewSecret", func(t *testing.T) {
resp, err = suite.cli.CreateNewSecret(&SecretBodyOpts{
Name: secretName,
Value: secretVal,
})
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 201, resp.StatusCode)

// update the secret if not a swarm cluster
if suite.cli.ClusterType != "swarm" {
suite.T().Run("IntTests/TestSecretsCRUD/UpdateSecret", func(t *testing.T) {
resp, err = suite.cli.UpdateSecret(&SecretBodyOpts{
Name: secretName,
Value: "updated_integration_test_secret_val",
})
})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
}

// delete the secret
suite.T().Run("IntTests/TestSecretsCRUD/DeleteSecret", func(t *testing.T) {
resp, err = suite.cli.DeleteSecret(&SecretNameBodyOpts{Name: secretName})
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
})
}
18 changes: 14 additions & 4 deletions go_faas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,21 @@ func (suite *GoFaasTestSuite) TestGetHealthz() {
}

func (suite *GoFaasTestSuite) TearDownSuite() {
// teardown functions
_, err := suite.cli.DeleteSystemFunction(&DeleteFunctionBodyOpts{FunctionName: "nodeinfo123456"})
if err != nil {
suite.T().Logf("error occurred while tearing down nodeinfo1235: %v", err)
_, err = suite.cli.DeleteSystemFunction(&DeleteFunctionBodyOpts{FunctionName: "yetanothernodeinfo"})
if err != nil {
suite.T().Logf("error occurred while tearing down yetanothernodeinfo: %v", err)
}
}
_, err = suite.cli.DeleteSystemFunction(&DeleteFunctionBodyOpts{FunctionName: "yetanothernodeinfo"})
if err != nil {
suite.T().Logf("error occurred while tearing down yetanothernodeinfo: %v", err)
}
_, err = suite.cli.DeleteSystemFunction(&DeleteFunctionBodyOpts{FunctionName: "integration_testnodeinfo"})
if err != nil {
suite.T().Logf("error occurred while tearing down integration_testnodeinfo: %v", err)
}

// teardown secrets
_, err = suite.cli.DeleteSecret(&SecretNameBodyOpts{Name: "secretkey101"})
if err != nil {
suite.T().Logf("Error tearing down secretkey101 : %v", err)
Expand All @@ -787,5 +793,9 @@ func (suite *GoFaasTestSuite) TearDownSuite() {
if err != nil {
suite.T().Logf("Error tearing down secretkey101 : %v", err)
}
_, err = suite.cli.DeleteSecret(&SecretNameBodyOpts{Name: "integration_test_secret"})
if err != nil {
suite.T().Logf("Error tearing down secretkey101 : %v", err)
}

}

0 comments on commit 25c5e77

Please sign in to comment.