mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* get rid of old format stuff, utils usage, fix up for fdk2.0 interface * pure agent format removal, TODO remove format field, fix up all tests * shitter's clogged * fix agent tests * start rolling through server tests * tests compile, some failures * remove json / content type detection on invoke/httptrigger, fix up tests * remove hello, fixup system tests the fucking status checker test just hangs and it's testing that it doesn't work so the test passes but the test doesn't pass fuck life it's not worth it * fix migration * meh * make dbhelper shut up about dbhelpers not being used * move fail status at least into main thread, jfc * fix status call to have FN_LISTENER also turns off the stdout/stderr blocking between calls, because it's impossible to debug without that (without syslog), now that stdout and stderr go to the same place (either to host stderr or nowhere) and isn't used for function output this shouldn't be a big fuss really * remove stdin * cleanup/remind: fixed bug where watcher would leak if container dies first * silence system-test logs until fail, fix datastore tests postgres does weird things with constraints when renaming tables, took the easy way out system-tests were loud as fuck and made you download a circleci text file of the logs, made them only yell when they goof * fix fdk-go dep for test image. fun * fix swagger and remove test about format * update all the gopkg files * add back FN_FORMAT for fdks that assert things. pfft * add useful error for functions that exit this error is really confounding because containers can exit for all manner of reason, we're just guessing that this is the most likely cause for now, and this error message should very likely change or be removed from the client path anyway (context.Canceled wasn't all that useful either, but anyway, I'd been hunting for this... so found it). added a test to avoid being publicly shamed for 1 line commits (beware...).
109 lines
2.7 KiB
Go
109 lines
2.7 KiB
Go
package models
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/leanovate/gopter"
|
|
"github.com/leanovate/gopter/gen"
|
|
"github.com/leanovate/gopter/prop"
|
|
)
|
|
|
|
func fnReflectType() reflect.Type {
|
|
fn := Fn{}
|
|
return reflect.TypeOf(fn)
|
|
}
|
|
|
|
func resourceConfigGenerator(t *testing.T) gopter.Gen {
|
|
fieldGens := make(map[string]gopter.Gen)
|
|
|
|
fieldGens["Memory"] = gen.UInt64()
|
|
fieldGens["Timeout"] = gen.Int32()
|
|
fieldGens["IdleTimeout"] = gen.Int32()
|
|
|
|
resourceConfig := ResourceConfig{}
|
|
resourceConfigFieldCount := reflect.TypeOf(resourceConfig).NumField()
|
|
|
|
if resourceConfigFieldCount != len(fieldGens) {
|
|
t.Fatalf("Fn struct field count, %d, does not match fn generator field count, %d", resourceConfigFieldCount, len(fieldGens))
|
|
}
|
|
|
|
return gen.Struct(reflect.TypeOf(resourceConfig), fieldGens)
|
|
}
|
|
|
|
func fnFieldGenerators(t *testing.T) map[string]gopter.Gen {
|
|
fieldGens := make(map[string]gopter.Gen)
|
|
|
|
fieldGens["ID"] = gen.AlphaString()
|
|
fieldGens["Name"] = gen.AlphaString()
|
|
fieldGens["AppID"] = gen.AlphaString()
|
|
fieldGens["Image"] = gen.AlphaString()
|
|
fieldGens["Config"] = configGenerator()
|
|
fieldGens["ResourceConfig"] = resourceConfigGenerator(t)
|
|
fieldGens["Annotations"] = annotationGenerator()
|
|
fieldGens["CreatedAt"] = datetimeGenerator()
|
|
fieldGens["UpdatedAt"] = datetimeGenerator()
|
|
|
|
fnFieldCount := fnReflectType().NumField()
|
|
|
|
if fnFieldCount != len(fieldGens) {
|
|
t.Fatalf("Fn struct field count, %d, does not match fn generator field count, %d", fnFieldCount, len(fieldGens))
|
|
}
|
|
|
|
return fieldGens
|
|
}
|
|
|
|
func fnGenerator(t *testing.T) gopter.Gen {
|
|
return gen.Struct(fnReflectType(), fnFieldGenerators(t))
|
|
}
|
|
|
|
func TestFnEquality(t *testing.T) {
|
|
properties := gopter.NewProperties(nil)
|
|
|
|
properties.Property("A fn should always equal itself", prop.ForAll(
|
|
func(fn Fn) bool {
|
|
return fn.Equals(&fn)
|
|
},
|
|
fnGenerator(t),
|
|
))
|
|
|
|
properties.Property("A fn should always equal a clone of itself", prop.ForAll(
|
|
func(fn Fn) bool {
|
|
clone := fn.Clone()
|
|
return fn.Equals(clone)
|
|
},
|
|
fnGenerator(t),
|
|
))
|
|
|
|
fnFieldGens := fnFieldGenerators(t)
|
|
|
|
properties.Property("A fn should never match a modified version of itself", prop.ForAll(
|
|
func(fn Fn) bool {
|
|
for fieldName, fieldGen := range fnFieldGens {
|
|
|
|
if fieldName == "CreatedAt" ||
|
|
fieldName == "UpdatedAt" {
|
|
continue
|
|
}
|
|
|
|
currentValue, newValue := novelValue(t, reflect.ValueOf(fn), fieldName, fieldGen)
|
|
|
|
clone := fn.Clone()
|
|
s := reflect.ValueOf(clone).Elem()
|
|
field := s.FieldByName(fieldName)
|
|
|
|
field.Set(newValue)
|
|
|
|
if fn.Equals(clone) {
|
|
t.Errorf("Changed field, %s, from {%v} to {%v}, but still equal.", fieldName, currentValue, newValue)
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
},
|
|
fnGenerator(t),
|
|
))
|
|
|
|
properties.TestingRun(t)
|
|
}
|