mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add support for Function and Trigger domain objects (#1060)
Vast commit, includes: * Introduces the Trigger domain entity. * Introduces the Fns domain entity. * V2 of the API for interacting with the new entities in swaggerv2.yml * Adds v2 end points for Apps to support PUT updates. * Rewrites the datastore level tests into a new pattern. * V2 routes use entity ID over name as the path parameter.
This commit is contained in:
51
api/models/trigger_test.go
Normal file
51
api/models/trigger_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var openEmptyJson = `{"id":"","name":"","app_id":"","fn_id":"","created_at":"0001-01-01T00:00:00.000Z","updated_at":"0001-01-01T00:00:00.000Z","type":"","source":""`
|
||||
|
||||
var triggerJsonCases = []struct {
|
||||
val *Trigger
|
||||
valString string
|
||||
}{
|
||||
{val: &Trigger{}, valString: openEmptyJson + "}"},
|
||||
}
|
||||
|
||||
func TestTriggerJsonMarshalling(t *testing.T) {
|
||||
for _, tc := range triggerJsonCases {
|
||||
v, err := json.Marshal(tc.val)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to marshal json into %s: %v", tc.valString, err)
|
||||
}
|
||||
if string(v) != tc.valString {
|
||||
t.Errorf("Invalid trigger value, expected %s, got %s", tc.valString, string(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var httpTrigger = &Trigger{Name: "name", AppID: "foo", FnID: "bar", Type: "http", Source: "baz"}
|
||||
var invalidTrigger = &Trigger{Name: "name", AppID: "foo", FnID: "bar", Type: "error", Source: "baz"}
|
||||
|
||||
var triggerValidateCases = []struct {
|
||||
val *Trigger
|
||||
valid bool
|
||||
}{
|
||||
{val: &Trigger{}, valid: false},
|
||||
{val: invalidTrigger, valid: false},
|
||||
{val: httpTrigger, valid: true},
|
||||
}
|
||||
|
||||
func TestTriggerValidate(t *testing.T) {
|
||||
for _, tc := range triggerValidateCases {
|
||||
v := tc.val.Validate()
|
||||
if v != nil && tc.valid {
|
||||
t.Errorf("Expected Trigger to be valid, but err (%s) returned. Trigger: %#v", v, tc.val)
|
||||
}
|
||||
if v == nil && !tc.valid {
|
||||
t.Errorf("Expected Trigger to be invalid, but no err returned. Trigger: %#v", tc.val)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user