Skip to content

Commit

Permalink
Update tests back
Browse files Browse the repository at this point in the history
  • Loading branch information
notfelineit committed Apr 25, 2024
1 parent 92a6cf9 commit 0ae2768
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 27 deletions.
51 changes: 33 additions & 18 deletions cmd/internal/planetscale_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ func TestCanGenerateInitialState_Sharded(t *testing.T) {
}

for _, shard := range shards {
expectedShardStates.Shards[shard] = &SerializedCursor{
Cursor: &psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
},
cursor, err := TableCursorToSerializedCursor(&psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
})
assert.NoError(t, err)
cursor.UnserializedCursor = &psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
}
expectedShardStates.Shards[shard] = cursor
}

assert.NoError(t, err)
Expand Down Expand Up @@ -88,13 +93,18 @@ func TestCanGenerateInitialState_CustomShards(t *testing.T) {
}

for _, shard := range configuredShards {
expectedShardStates.Shards[shard] = &SerializedCursor{
Cursor: &psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
},
cursor, err := TableCursorToSerializedCursor(&psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
})
assert.NoError(t, err)
cursor.UnserializedCursor = &psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
}
expectedShardStates.Shards[shard] = cursor
}

assert.NoError(t, err)
Expand All @@ -119,13 +129,18 @@ func TestCanGenerateInitialState_Unsharded(t *testing.T) {
}

for _, shard := range shards {
expectedShardStates.Shards[shard] = &SerializedCursor{
Cursor: &psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
},
cursor, err := TableCursorToSerializedCursor(&psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
})
assert.NoError(t, err)
cursor.UnserializedCursor = &psdbconnect.TableCursor{
Shard: shard,
Keyspace: "connect-test",
Position: "",
}
expectedShardStates.Shards[shard] = cursor
}

assert.NoError(t, err)
Expand Down
36 changes: 27 additions & 9 deletions cmd/internal/planetscale_edge_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func TestRead_CanPeekBeforeRead(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, tc, sc.Cursor)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
assert.False(t, tma.PingContextFnInvoked)
assert.False(t, tma.GetVitessTabletsFnInvoked)
Expand Down Expand Up @@ -97,7 +99,9 @@ func TestRead_CanEarlyExitIfNoNewVGtidInPeek(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, tc, sc.Cursor)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
}

Expand Down Expand Up @@ -141,7 +145,9 @@ func TestRead_CanPickPrimaryForShardedKeyspaces(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, tc, sc.Cursor)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
assert.False(t, tma.PingContextFnInvoked)
assert.False(t, tma.GetVitessTabletsFnInvoked)
Expand Down Expand Up @@ -188,7 +194,9 @@ func TestRead_CanPickReplicaForShardedKeyspaces(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, tc, sc.Cursor)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
assert.False(t, tma.PingContextFnInvoked)
assert.False(t, tma.GetVitessTabletsFnInvoked)
Expand Down Expand Up @@ -364,7 +372,9 @@ func TestRead_CanPickPrimaryForUnshardedKeyspaces(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, tc, sc.Cursor)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
assert.False(t, tma.PingContextFnInvoked)
assert.False(t, tma.GetVitessTabletsFnInvoked)
Expand Down Expand Up @@ -413,7 +423,9 @@ func TestRead_CanPickReplicaForUnshardedKeyspaces(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, tc, sc.Cursor)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
assert.False(t, tma.PingContextFnInvoked)
assert.False(t, tma.GetVitessTabletsFnInvoked)
Expand Down Expand Up @@ -458,7 +470,9 @@ func TestRead_CanReturnOriginalCursorIfNoNewFound(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, tc, sc.Cursor)
esc, err := TableCursorToSerializedCursor(tc)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 1, cc.syncFnInvokedCount)
}

Expand Down Expand Up @@ -507,7 +521,9 @@ func TestRead_CanReturnNewCursorIfNewFound(t *testing.T) {
}
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, tc)
assert.NoError(t, err)
assert.Equal(t, newTC, sc.Cursor)
esc, err := TableCursorToSerializedCursor(newTC)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 2, cc.syncFnInvokedCount)
}

Expand Down Expand Up @@ -590,7 +606,9 @@ func TestRead_CanStopAtWellKnownCursor(t *testing.T) {
sc, err := ped.Read(context.Background(), os.Stdout, ps, cs, responses[0].Cursor)
assert.NoError(t, err)
// sync should start at the first vgtid
assert.Equal(t, responses[nextVGtidPosition].Cursor, sc.Cursor)
esc, err := TableCursorToSerializedCursor(responses[nextVGtidPosition].Cursor)
assert.NoError(t, err)
assert.Equal(t, esc, sc)
assert.Equal(t, 2, cc.syncFnInvokedCount)

logLines := tal.logMessages[LOGLEVEL_INFO]
Expand Down

0 comments on commit 0ae2768

Please sign in to comment.