diff --git a/helpers.go b/byte_utils.go similarity index 100% rename from helpers.go rename to byte_utils.go diff --git a/example/main.go b/example/main.go index be76eb5..02cbd09 100644 --- a/example/main.go +++ b/example/main.go @@ -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", diff --git a/go_faas_integration_test.go b/go_faas_integration_test.go new file mode 100644 index 0000000..9b6ec3f --- /dev/null +++ b/go_faas_integration_test.go @@ -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) + }) +} diff --git a/go_faas_test.go b/go_faas_test.go index 612f7cd..8c201c8 100644 --- a/go_faas_test.go +++ b/go_faas_test.go @@ -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) @@ -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) + } }