mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Timestamps on apps / routes (#614)
* route updated_at * add app created at, fix some route updated_at bugs * add app updated_at TODO need to add tests through front end TODO for validation we don't really want to use the validate wrapper since it's a programmer error and not a user error, hopefully tests block this. * add tests for timestamps to exist / change on apps&routes * route equals at done, fix tests wit dis * fix up the equals sugar * add swagger * fix rebase * precisely allocate maps in clone * vetted * meh * fix api tests
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/fnproject/fn/api/datastore"
|
||||
"github.com/fnproject/fn/api/logs"
|
||||
@@ -49,6 +50,46 @@ func (test *routeTestCase) run(t *testing.T, i int, buf *bytes.Buffer) {
|
||||
i, test.expectedError, resp.Error.Message)
|
||||
}
|
||||
}
|
||||
|
||||
if test.expectedCode == http.StatusOK {
|
||||
var rwrap models.RouteWrapper
|
||||
err := json.NewDecoder(rec.Body).Decode(&rwrap)
|
||||
if err != nil {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: error decoding body for 'ok' json, it was a lie: %v", i, err)
|
||||
}
|
||||
|
||||
route := rwrap.Route
|
||||
if test.method == http.MethodPost {
|
||||
// IsZero() doesn't really work, this ensures it's not unset as long as we're not in 1970
|
||||
if time.Time(route.CreatedAt).Before(time.Now().Add(-1 * time.Hour)) {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: expected created_at to be set on route, it wasn't: %s", i, route.CreatedAt)
|
||||
}
|
||||
if !(time.Time(route.CreatedAt)).Equal(time.Time(route.UpdatedAt)) {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: expected updated_at to be set and same as created at, it wasn't: %s %s", i, route.CreatedAt, route.UpdatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
if test.method == http.MethodPatch {
|
||||
// IsZero() doesn't really work, this ensures it's not unset as long as we're not in 1970
|
||||
if time.Time(route.UpdatedAt).Before(time.Now().Add(-1 * time.Hour)) {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: expected updated_at to be set on route, it wasn't: %s", i, route.UpdatedAt)
|
||||
}
|
||||
|
||||
// this isn't perfect, since a PATCH could succeed without updating any
|
||||
// fields (among other reasons), but just don't make a test for that or
|
||||
// special case (the body or smth) to ignore it here!
|
||||
// this is a decent approximation that the timestamp gets changed
|
||||
if (time.Time(route.UpdatedAt)).Equal(time.Time(route.CreatedAt)) {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: expected updated_at to not be the same as created at, it wasn't: %s %s", i, route.CreatedAt, route.UpdatedAt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cancel()
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user