Skip to content

Commit

Permalink
some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroshade committed Oct 11, 2023
1 parent 6023e54 commit a4e6037
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion table/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions table/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions table/refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 12 additions & 2 deletions table/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,15 +139,16 @@ 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)
}
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 {
Expand Down
10 changes: 10 additions & 0 deletions table/snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit a4e6037

Please sign in to comment.