Copy logs up to v2 endpoints (#1207)

Copies the log endpoints up to the V2 endpoints, in a similar way to
the call endpoints.

The main change is to when logs are inserted into S3. The signature of
the function has been changed to take the whole call object, rather
than just the app and call id's. This allows the function to switch
between calls for Routes and those for Fns. Obviously this switching
can be removed when v1 is removed.

In the sql implementation it inserts with both appID and fnID, this
allows the two get's to work, and the down grade of the
migration. When the v1 logs are removed, the appId can be dropped.

The log fetch test and error messages have been changed to be FnID specific.
This commit is contained in:
Tom Coupland
2018-09-13 10:30:10 +01:00
committed by GitHub
parent ac11d42e56
commit a0ccc4d7c4
15 changed files with 186 additions and 58 deletions

View File

@@ -145,11 +145,11 @@ func Test(t *testing.T, fnl models.LogStore) {
call.ID = id.New().String()
logText := "test"
log := strings.NewReader(logText)
err := fnl.InsertLog(ctx, call.AppID, call.ID, log)
err := fnl.InsertLog(ctx, call, log)
if err != nil {
t.Fatalf("Test InsertLog(ctx, call.ID, logText): unexpected error during inserting log `%v`", err)
}
logEntry, err := fnl.GetLog(ctx, call.AppID, call.ID)
logEntry, err := fnl.GetLog(ctx, call.FnID, call.ID)
var b bytes.Buffer
io.Copy(&b, logEntry)
if !strings.Contains(b.String(), logText) {
@@ -160,7 +160,7 @@ func Test(t *testing.T, fnl models.LogStore) {
t.Run("call-log-not-found", func(t *testing.T) {
call.ID = id.New().String()
_, err := fnl.GetLog(ctx, call.AppID, call.ID)
_, err := fnl.GetLog(ctx, call.FnID, call.ID)
if err != models.ErrCallLogNotFound {
t.Fatal("GetLog should return not found, but got:", err)
}
@@ -172,7 +172,7 @@ func Test(t *testing.T, fnl models.LogStore) {
call.Error = "ya dun goofed"
call.StartedAt = common.DateTime(time.Now())
call.CompletedAt = common.DateTime(time.Now())
call.AppID = testApp.Name
call.AppID = testApp.ID
call.FnID = testFn.ID
t.Run("call-insert", func(t *testing.T) {
@@ -212,7 +212,7 @@ func Test(t *testing.T, fnl models.LogStore) {
t.Fatalf("Test GetCall: completed_at mismatch `%v` `%v`", call.CompletedAt, newCall.CompletedAt)
}
if call.AppID != newCall.AppID {
t.Fatalf("Test GetCall: app_name mismatch `%v` `%v`", call.AppID, newCall.AppID)
t.Fatalf("Test GetCall: fn id mismatch `%v` `%v`", call.FnID, newCall.FnID)
}
if call.Path != newCall.Path {
t.Fatalf("Test GetCall: path mismatch `%v` `%v`", call.Path, newCall.Path)