2021-03-31 20:05:43 +00:00
|
|
|
// +build !race
|
|
|
|
|
2021-03-31 19:15:03 +00:00
|
|
|
package foolsday3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLambda(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
var doNotPrint bool
|
|
|
|
var validateLambdaFunc = func(end time.Time) bool {
|
|
|
|
return time.Now() == end
|
|
|
|
}
|
|
|
|
result := lambda(ctx)
|
|
|
|
end := time.Now()
|
|
|
|
if validateLambdaFunc(end) == true {
|
|
|
|
t.Logf("[%s] Great! Your function is very fast!", end.Format("15:04:05.999999"))
|
|
|
|
if doNotPrint != true {
|
|
|
|
t.Log("Congrats!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Log(result)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
t.Logf("[%s] result of your slow function:", end.Format("15:04:05.999999"))
|
|
|
|
t.Log(result)
|
|
|
|
t.FailNow()
|
|
|
|
}
|