From a4e6037d52d1cbeea6d4c94f68738e0f9ec4879d Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Fri, 6 Oct 2023 13:36:34 -0400 Subject: [PATCH] some more tests --- table/metadata_test.go | 2 +- table/refs.go | 4 ++-- table/refs_test.go | 35 +++++++++++++++++++++++++++++++++++ table/snapshots.go | 14 ++++++++++++-- table/snapshots_test.go | 10 ++++++++++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/table/metadata_test.go b/table/metadata_test.go index e8dac51..6547baa 100644 --- a/table/metadata_test.go +++ b/table/metadata_test.go @@ -401,7 +401,7 @@ func TestV2RefCreation(t *testing.T) { var meta table.MetadataV2 require.NoError(t, json.Unmarshal([]byte(ExampleTableMetadataV2), &meta)) - maxRefAge := 10000000 + maxRefAge := int64(10000000) assert.Equal(t, map[string]table.SnapshotRef{ "main": { SnapshotID: 3055729675574597004, diff --git a/table/refs.go b/table/refs.go index 715bae9..cf63efc 100644 --- a/table/refs.go +++ b/table/refs.go @@ -41,8 +41,8 @@ type SnapshotRef struct { SnapshotID int64 `json:"snapshot-id"` SnapshotRefType RefType `json:"type"` MinSnapshotsToKeep *int `json:"min-snapshots-to-keep,omitempty"` - MaxSnapshotAgeMs *int `json:"max-snapshot-age-ms,omitempty"` - MaxRefAgeMs *int `json:"max-ref-age-ms,omitempty"` + MaxSnapshotAgeMs *int64 `json:"max-snapshot-age-ms,omitempty"` + MaxRefAgeMs *int64 `json:"max-ref-age-ms,omitempty"` } func (s *SnapshotRef) UnmarshalJSON(b []byte) error { diff --git a/table/refs_test.go b/table/refs_test.go index bb61b1d..d8b54e4 100644 --- a/table/refs_test.go +++ b/table/refs_test.go @@ -35,3 +35,38 @@ func TestInvalidSnapshotRefType(t *testing.T) { err := json.Unmarshal([]byte(ref), &snapRef) assert.ErrorIs(t, err, table.ErrInvalidRefType) } + +func TestSnapshotBranchRef(t *testing.T) { + ref := `{ + "snapshot-id": 3051729675574597004, + "type": "branch" + }` + + var snapRef table.SnapshotRef + err := json.Unmarshal([]byte(ref), &snapRef) + assert.NoError(t, err) + + assert.Equal(t, table.BranchRef, snapRef.SnapshotRefType) + assert.Equal(t, int64(3051729675574597004), snapRef.SnapshotID) + assert.Nil(t, snapRef.MinSnapshotsToKeep) + assert.Nil(t, snapRef.MaxRefAgeMs) + assert.Nil(t, snapRef.MaxSnapshotAgeMs) +} + +func TestSnapshotTagRef(t *testing.T) { + ref := `{ + "snapshot-id": 3051729675574597004, + "type": "tag", + "min-snapshots-to-keep": 10 + }` + + var snapRef table.SnapshotRef + err := json.Unmarshal([]byte(ref), &snapRef) + assert.NoError(t, err) + + assert.Equal(t, table.TagRef, snapRef.SnapshotRefType) + assert.Equal(t, int64(3051729675574597004), snapRef.SnapshotID) + assert.Equal(t, 10, *snapRef.MinSnapshotsToKeep) + assert.Nil(t, snapRef.MaxRefAgeMs) + assert.Nil(t, snapRef.MaxSnapshotAgeMs) +} diff --git a/table/snapshots.go b/table/snapshots.go index c539c84..26dc8d2 100644 --- a/table/snapshots.go +++ b/table/snapshots.go @@ -62,6 +62,15 @@ type Summary struct { Properties map[string]string } +func (s *Summary) String() string { + out := string(s.Operation) + if s.Properties != nil { + data, _ := json.Marshal(s.Properties) + out += ", " + string(data) + } + return out +} + func (s *Summary) Equals(other *Summary) bool { if s == other { return true @@ -130,7 +139,7 @@ func (s Snapshot) String() string { ) if s.Summary != nil { - op = string(s.Summary.Operation) + ": " + op = s.Summary.String() + ": " } if s.ParentSnapshotID != nil { parent = ", parent_id=" + strconv.FormatInt(*s.ParentSnapshotID, 10) @@ -138,7 +147,8 @@ func (s Snapshot) String() string { if s.SchemaID != nil { schema = ", schema_id=" + strconv.Itoa(*s.SchemaID) } - return fmt.Sprintf("%sid=%d%s%s", op, s.SnapshotID, parent, schema) + return fmt.Sprintf("%sid=%d%s%s, sequence_number=%d, timestamp_ms=%d, manifest_list=%s", + op, s.SnapshotID, parent, schema, s.SequenceNumber, s.TimestampMs, s.ManifestList) } func (s Snapshot) Equals(other Snapshot) bool { diff --git a/table/snapshots_test.go b/table/snapshots_test.go index 8be7baa..f79f977 100644 --- a/table/snapshots_test.go +++ b/table/snapshots_test.go @@ -103,3 +103,13 @@ func TestInvalidOperation(t *testing.T) { assert.ErrorIs(t, err, table.ErrInvalidOperation) assert.ErrorContains(t, err, "found 'foobar'") } + +func TestSnapshotString(t *testing.T) { + snapshot := testSnapshot() + assert.Equal(t, `append: id=25, parent_id=19, schema_id=3, sequence_number=200, timestamp_ms=1602638573590, manifest_list=s3:/a/b/c.avro`, + snapshot.String()) + + snapshot = testSnapshotWithProperties() + assert.Equal(t, `append, {"foo":"bar"}: id=25, parent_id=19, schema_id=3, sequence_number=200, timestamp_ms=1602638573590, manifest_list=s3:/a/b/c.avro`, + snapshot.String()) +}