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 2 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
150 changes: 150 additions & 0 deletions go_faas_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// +build integration

package go_faas

import "github.com/stretchr/testify/assert"

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

// get functions
akshaydotsh marked this conversation as resolved.
Show resolved Hide resolved
resp, err := suite.cli.GetSystemFunctions()
if err != nil {
suite.T().Fatalf("GetSystemFunctions/Error: %v", err)
}
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,
}
resp, err = suite.cli.CreateSystemFunctions(def)
if err != nil {
akshaydotsh marked this conversation as resolved.
Show resolved Hide resolved
suite.T().Fatalf("CreateSystemFunctions/Error: %v", err)
}
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)

// get function summary
resp, err = suite.cli.GetFunctionSummary(funcName)
if err != nil {
suite.T().Fatalf("CreateSystemFunctions/Error: %v", err)
akshaydotsh marked this conversation as resolved.
Show resolved Hide resolved
}
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",
},
}
resp, err = suite.cli.UpdateSystemFunctions(update)
if err != nil {
suite.T().Fatalf("UpdateSystemFunctions/Error: %v", err)
}
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)

// scale up the func
resp, err = suite.cli.ScaleFunction(&ScaleFunctionBodyOpts{
Service: funcName,
Replicas: 3,
})
if err != nil {
suite.T().Fatalf("ScaleFunction/Up/Error: %v", err)
}
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)

// scale down the func
resp, err = suite.cli.ScaleFunction(&ScaleFunctionBodyOpts{
Service: funcName,
Replicas: 1,
})
if err != nil {
suite.T().Fatalf("ScaleFunction/Down/Error: %v", err)
}
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 202, resp.StatusCode)

// delete the func
resp, err = suite.cli.DeleteSystemFunction(&DeleteFunctionBodyOpts{FunctionName: funcName})
if err != nil {
suite.T().Fatalf("DeleteSystemFunction/Error: %v", err)
}
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
resp, err := suite.cli.GetSecrets()
if err != nil {
suite.T().Errorf("GetSecrets/Error: %v", err)
}
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), resp.StatusCode, 200)

// create new secret
resp, err = suite.cli.CreateNewSecret(&SecretBodyOpts{
Name: secretName,
Value: secretVal,
})
if err != nil {
suite.T().Fatalf("CreateNewSecret/Error: %v", err)
}
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" {
resp, err = suite.cli.UpdateSecret(&SecretBodyOpts{
Name: secretName,
Value: "updated_integration_test_secret_val",
})
if err != nil {
suite.T().Fatalf("UpdateSecret/Error: %v", err)
}
assert.Equal(suite.T(), nil, err)
assert.Equal(suite.T(), 200, resp.StatusCode)
}

// delete the secret
resp, err = suite.cli.DeleteSecret(&SecretNameBodyOpts{Name: secretName})
if err != nil {
suite.T().Fatalf("DeleteSecret/Error: %v", err)
}
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)
}

}