github.com/graphql-editor/azure-functions-golang-worker@v0.1.0/worker/function_info_test.go (about) 1 package worker_test 2 3 import ( 4 "testing" 5 6 "github.com/graphql-editor/azure-functions-golang-worker/rpc" 7 "github.com/graphql-editor/azure-functions-golang-worker/worker" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestNewFunctionInfo(t *testing.T) { 12 fi, err := worker.NewFunctionInfo( 13 &rpc.RpcFunctionMetadata{ 14 Name: "function", 15 Directory: "mock/path", 16 ScriptFile: "main.go", 17 Bindings: map[string]*rpc.BindingInfo{ 18 "trigger": &rpc.BindingInfo{ 19 Type: "httpTrigger", 20 Direction: rpc.BindingInfo_in, 21 DataType: rpc.BindingInfo_binary, 22 }, 23 "input": &rpc.BindingInfo{ 24 Type: "blob", 25 Direction: rpc.BindingInfo_in, 26 DataType: rpc.BindingInfo_string, 27 }, 28 "output": &rpc.BindingInfo{ 29 Type: "blob", 30 Direction: rpc.BindingInfo_out, 31 DataType: rpc.BindingInfo_stream, 32 }, 33 "inputoutput": &rpc.BindingInfo{ 34 Type: "blob", 35 Direction: rpc.BindingInfo_inout, 36 DataType: rpc.BindingInfo_undefined, 37 }, 38 "$return": &rpc.BindingInfo{ 39 Type: "http", 40 Direction: rpc.BindingInfo_out, 41 DataType: rpc.BindingInfo_undefined, 42 }, 43 }, 44 }, 45 ) 46 assert.NoError(t, err) 47 assert.Equal(t, worker.FunctionInfo{ 48 Name: "function", 49 Directory: "mock/path", 50 ScriptFile: "main.go", 51 EntryPoint: "Function", 52 TriggerBindingName: "trigger", 53 Trigger: worker.BindingInfo{ 54 Type: "httpTrigger", 55 Direction: worker.In, 56 DataType: worker.Binary, 57 }, 58 InputBindings: worker.Bindings{ 59 "input": { 60 Type: "blob", 61 Direction: worker.In, 62 DataType: worker.String, 63 }, 64 "inputoutput": { 65 Type: "blob", 66 Direction: worker.InOut, 67 DataType: worker.Undefined, 68 }, 69 }, 70 OutputBindings: worker.Bindings{ 71 "output": { 72 Type: "blob", 73 Direction: worker.Out, 74 DataType: worker.Stream, 75 }, 76 "inputoutput": { 77 Type: "blob", 78 Direction: worker.InOut, 79 DataType: worker.Undefined, 80 }, 81 "$return": { 82 Type: "http", 83 Direction: worker.Out, 84 DataType: worker.Undefined, 85 }, 86 }, 87 }, fi) 88 } 89 90 func TestEntrypointValidation(t *testing.T) { 91 fi, err := worker.NewFunctionInfo(&rpc.RpcFunctionMetadata{ 92 EntryPoint: "entryPoint", 93 }) 94 assert.NoError(t, err) 95 assert.Equal(t, "EntryPoint", fi.EntryPoint) 96 _, err = worker.NewFunctionInfo(&rpc.RpcFunctionMetadata{ 97 EntryPoint: "not a valid entry point", 98 }) 99 assert.Error(t, err) 100 }