https://github.com/nuclio/nuclio-test-go
processor emulation wrapper for Go functions local debug & development
https://github.com/nuclio/nuclio-test-go
Last synced: 3 months ago
JSON representation
processor emulation wrapper for Go functions local debug & development
- Host: GitHub
- URL: https://github.com/nuclio/nuclio-test-go
- Owner: nuclio
- License: apache-2.0
- Created: 2018-01-30T20:00:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-03T13:04:21.000Z (about 3 years ago)
- Last Synced: 2025-03-25T15:50:12.365Z (7 months ago)
- Language: Go
- Size: 13.7 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nuclio function wrapper
Test nuclio functions locally of as part of Go testing
# Usage, Golang unit testing framework:
```golang
package mainimport (
"testing"
"github.com/nuclio/nuclio-test-go"
)func TestName(t *testing.T) {
// data binding for V3IO data containers, optional (use nil instead of &data)
data := nutest.DataBind{Name:"db0", Url:"", Container:"x"}// Create TestContext and specify the function name, verbose, data
tc, err := nutest.NewTestContext(MyHandler, true, &data )
if err != nil {
t.Fail()
}// Optional, initialize context must have a function in the form:
// InitContext(context *nuclio.Context) error
err = tc.InitContext(InitContext)
if err != nil {
t.Fail()
}// Create a new test event
testEvent := nutest.TestEvent{
Path: "/some/path",
Body: []byte("1234"),
Headers:map[string]interface{}{"first": "string"},
}
// invoke the tested function with the new event and log it's output
resp, err := tc.Invoke(&testEvent)
tc.Logger.InfoWith("Run complete", "resp", resp, "err", err)
}
```# Usage, called from another program:
```golang
package mainimport (
"github.com/nuclio/nuclio-test-go"
)func main() {
// data binding for V3IO data containers, optional (use nil instead of &data)
data := nutest.DataBind{Name:"db0", Url:""", Container:"x"}// Create TestContext and specify the function name, verbose, data
tc, err := nutest.NewTestContext(MyHandler, true, &data )
if err != nil {
panic(err)
}// Create a new test event
testEvent := nutest.TestEvent{
Path: "/some/path",
Body: []byte("1234"),
Headers:map[string]interface{}{"first": "something"},
}
// invoke the tested function with the new event and log it's output
resp, err := tc.Invoke(&testEvent)
tc.Logger.InfoWith("Run complete", "resp", resp, "err", err)
}
```