Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Go-SDK for OpenFass API #9

Merged
merged 3 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
akshaydotsh marked this conversation as resolved.
Show resolved Hide resolved
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)
}

}