laskoviymishka commented on code in PR #1068:
URL: https://github.com/apache/iceberg-go/pull/1068#discussion_r3236917950
##########
cmd/iceberg/branch_tag.go:
##########
@@ -19,21 +19,135 @@ package main
import (
"context"
+ "encoding/json"
"errors"
+ "fmt"
"os"
"github.com/apache/iceberg-go/catalog"
+ "github.com/apache/iceberg-go/table"
+ "github.com/pterm/pterm"
)
-func runBranch(_ context.Context, output Output, _ catalog.Catalog, _
*BranchCmd) {
- output.Error(errors.New("branch: not yet implemented"))
- os.Exit(1)
+func runBranch(ctx context.Context, output Output, cat catalog.Catalog, cmd
*BranchCmd) {
+ switch {
+ case cmd.Create != nil:
+ runBranchCreate(ctx, output, cat, cmd.Create)
+ }
}
-func runTag(_ context.Context, output Output, _ catalog.Catalog, _ *TagCmd) {
- output.Error(errors.New("tag: not yet implemented"))
- os.Exit(1)
+func runTag(ctx context.Context, output Output, cat catalog.Catalog, cmd
*TagCmd) {
+ switch {
+ case cmd.Create != nil:
+ runTagCreate(ctx, output, cat, cmd.Create)
+ }
}
-func (textOutput) RefCreated(_ RefCreatedResult) {}
-func (jsonOutput) RefCreated(_ RefCreatedResult) {}
+func runBranchCreate(ctx context.Context, output Output, cat catalog.Catalog,
cmd *BranchCreateCmd) {
+ tbl := loadTable(ctx, output, cat, cmd.TableID)
+ meta := tbl.Metadata()
+
+ snapshotID := resolveSnapshotID(output, tbl, cmd.SnapshotID)
+
+ var maxRefAgeMs int64
+ if cmd.MaxRefAge != "" {
+ d, err := parseDuration(cmd.MaxRefAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-ref-age: %w",
err))
+ os.Exit(1)
+ }
+
+ maxRefAgeMs = d.Milliseconds()
+ }
+
+ var maxSnapshotAgeMs int64
+ if cmd.MaxSnapshotAge != "" {
+ d, err := parseDuration(cmd.MaxSnapshotAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-snapshot-age:
%w", err))
+ os.Exit(1)
+ }
+
+ maxSnapshotAgeMs = d.Milliseconds()
+ }
+
+ var minSnapshotsToKeep int
+ if cmd.MinSnapshotsToKeep != nil {
+ minSnapshotsToKeep = *cmd.MinSnapshotsToKeep
+ }
+
+ update := table.NewSetSnapshotRefUpdate(cmd.BranchName, snapshotID,
table.BranchRef,
+ maxRefAgeMs, maxSnapshotAgeMs, minSnapshotsToKeep)
+ reqs := []table.Requirement{table.AssertTableUUID(meta.TableUUID())}
Review Comment:
Requirements slice is just `AssertTableUUID`, so `branch create` silently
overwrites an existing ref — `iceberg branch create db.t main --snapshot-id
999` rewrites `main`. Two-part fix:
1. Pre-flight check `meta.Refs()` for `cmd.BranchName` and error out with
`ref %q already exists` if present.
2. Add `table.AssertRefSnapshotID(cmd.BranchName, nil)` to `reqs` so REST
catalogs reject concurrent creates server-side too.
Java's `UpdateSnapshotReferencesOperation.createBranch` uses
`Preconditions.checkArgument(existingRef == null, ...)`; PyIceberg's
`create_branch` emits `AssertRefSnapshotId(snapshot_id=None, ref=ref_name)`.
Same applies to `runTagCreate` below (line 115).
##########
cmd/iceberg/branch_tag.go:
##########
@@ -19,21 +19,135 @@ package main
import (
"context"
+ "encoding/json"
"errors"
+ "fmt"
"os"
"github.com/apache/iceberg-go/catalog"
+ "github.com/apache/iceberg-go/table"
+ "github.com/pterm/pterm"
)
-func runBranch(_ context.Context, output Output, _ catalog.Catalog, _
*BranchCmd) {
- output.Error(errors.New("branch: not yet implemented"))
- os.Exit(1)
+func runBranch(ctx context.Context, output Output, cat catalog.Catalog, cmd
*BranchCmd) {
+ switch {
+ case cmd.Create != nil:
+ runBranchCreate(ctx, output, cat, cmd.Create)
+ }
}
-func runTag(_ context.Context, output Output, _ catalog.Catalog, _ *TagCmd) {
- output.Error(errors.New("tag: not yet implemented"))
- os.Exit(1)
+func runTag(ctx context.Context, output Output, cat catalog.Catalog, cmd
*TagCmd) {
+ switch {
+ case cmd.Create != nil:
+ runTagCreate(ctx, output, cat, cmd.Create)
+ }
}
-func (textOutput) RefCreated(_ RefCreatedResult) {}
-func (jsonOutput) RefCreated(_ RefCreatedResult) {}
+func runBranchCreate(ctx context.Context, output Output, cat catalog.Catalog,
cmd *BranchCreateCmd) {
Review Comment:
`BranchCreateCmd` and `TagCreateCmd` are the only write commands in the
series without a `Yes bool` / `confirmAction` gate. Once the existence check
above is added the destructive surface shrinks, but the pattern asymmetry will
surprise the next contributor. Add `Yes bool \`help:"skip confirmation
prompt"\`` to both structs in `maintenance.go` and call `confirmAction("Create
branch %s on %s?", cmd.Yes)` before `CommitTable`.
##########
cmd/iceberg/branch_tag.go:
##########
@@ -19,21 +19,135 @@ package main
import (
"context"
+ "encoding/json"
"errors"
+ "fmt"
"os"
"github.com/apache/iceberg-go/catalog"
+ "github.com/apache/iceberg-go/table"
+ "github.com/pterm/pterm"
)
-func runBranch(_ context.Context, output Output, _ catalog.Catalog, _
*BranchCmd) {
- output.Error(errors.New("branch: not yet implemented"))
- os.Exit(1)
+func runBranch(ctx context.Context, output Output, cat catalog.Catalog, cmd
*BranchCmd) {
+ switch {
+ case cmd.Create != nil:
+ runBranchCreate(ctx, output, cat, cmd.Create)
+ }
}
-func runTag(_ context.Context, output Output, _ catalog.Catalog, _ *TagCmd) {
- output.Error(errors.New("tag: not yet implemented"))
- os.Exit(1)
+func runTag(ctx context.Context, output Output, cat catalog.Catalog, cmd
*TagCmd) {
+ switch {
+ case cmd.Create != nil:
+ runTagCreate(ctx, output, cat, cmd.Create)
+ }
}
-func (textOutput) RefCreated(_ RefCreatedResult) {}
-func (jsonOutput) RefCreated(_ RefCreatedResult) {}
+func runBranchCreate(ctx context.Context, output Output, cat catalog.Catalog,
cmd *BranchCreateCmd) {
+ tbl := loadTable(ctx, output, cat, cmd.TableID)
+ meta := tbl.Metadata()
+
+ snapshotID := resolveSnapshotID(output, tbl, cmd.SnapshotID)
+
+ var maxRefAgeMs int64
+ if cmd.MaxRefAge != "" {
+ d, err := parseDuration(cmd.MaxRefAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-ref-age: %w",
err))
+ os.Exit(1)
+ }
+
+ maxRefAgeMs = d.Milliseconds()
+ }
+
+ var maxSnapshotAgeMs int64
+ if cmd.MaxSnapshotAge != "" {
+ d, err := parseDuration(cmd.MaxSnapshotAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-snapshot-age:
%w", err))
+ os.Exit(1)
+ }
+
+ maxSnapshotAgeMs = d.Milliseconds()
+ }
+
+ var minSnapshotsToKeep int
+ if cmd.MinSnapshotsToKeep != nil {
+ minSnapshotsToKeep = *cmd.MinSnapshotsToKeep
+ }
+
+ update := table.NewSetSnapshotRefUpdate(cmd.BranchName, snapshotID,
table.BranchRef,
+ maxRefAgeMs, maxSnapshotAgeMs, minSnapshotsToKeep)
+ reqs := []table.Requirement{table.AssertTableUUID(meta.TableUUID())}
+
+ if _, _, err := cat.CommitTable(ctx, tbl.Identifier(), reqs,
[]table.Update{update}); err != nil {
+ output.Error(fmt.Errorf("create branch failed: %w", err))
Review Comment:
`"create branch failed"` (and `"create tag failed"` at line 118) inverts the
verb/object order used everywhere else in this package — `"failed to create
table"`, `"failed to parse properties"`, etc. Suggested: `fmt.Errorf("failed to
create branch: %w", err)` for grep consistency.
##########
cmd/iceberg/branch_tag.go:
##########
@@ -19,21 +19,135 @@ package main
import (
"context"
+ "encoding/json"
"errors"
+ "fmt"
"os"
"github.com/apache/iceberg-go/catalog"
+ "github.com/apache/iceberg-go/table"
+ "github.com/pterm/pterm"
)
-func runBranch(_ context.Context, output Output, _ catalog.Catalog, _
*BranchCmd) {
- output.Error(errors.New("branch: not yet implemented"))
- os.Exit(1)
+func runBranch(ctx context.Context, output Output, cat catalog.Catalog, cmd
*BranchCmd) {
+ switch {
+ case cmd.Create != nil:
+ runBranchCreate(ctx, output, cat, cmd.Create)
+ }
}
-func runTag(_ context.Context, output Output, _ catalog.Catalog, _ *TagCmd) {
- output.Error(errors.New("tag: not yet implemented"))
- os.Exit(1)
+func runTag(ctx context.Context, output Output, cat catalog.Catalog, cmd
*TagCmd) {
+ switch {
+ case cmd.Create != nil:
+ runTagCreate(ctx, output, cat, cmd.Create)
+ }
}
-func (textOutput) RefCreated(_ RefCreatedResult) {}
-func (jsonOutput) RefCreated(_ RefCreatedResult) {}
+func runBranchCreate(ctx context.Context, output Output, cat catalog.Catalog,
cmd *BranchCreateCmd) {
+ tbl := loadTable(ctx, output, cat, cmd.TableID)
+ meta := tbl.Metadata()
+
+ snapshotID := resolveSnapshotID(output, tbl, cmd.SnapshotID)
+
+ var maxRefAgeMs int64
+ if cmd.MaxRefAge != "" {
+ d, err := parseDuration(cmd.MaxRefAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-ref-age: %w",
err))
+ os.Exit(1)
+ }
+
+ maxRefAgeMs = d.Milliseconds()
+ }
+
+ var maxSnapshotAgeMs int64
+ if cmd.MaxSnapshotAge != "" {
+ d, err := parseDuration(cmd.MaxSnapshotAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-snapshot-age:
%w", err))
+ os.Exit(1)
+ }
+
+ maxSnapshotAgeMs = d.Milliseconds()
+ }
+
+ var minSnapshotsToKeep int
+ if cmd.MinSnapshotsToKeep != nil {
+ minSnapshotsToKeep = *cmd.MinSnapshotsToKeep
+ }
+
+ update := table.NewSetSnapshotRefUpdate(cmd.BranchName, snapshotID,
table.BranchRef,
+ maxRefAgeMs, maxSnapshotAgeMs, minSnapshotsToKeep)
+ reqs := []table.Requirement{table.AssertTableUUID(meta.TableUUID())}
+
+ if _, _, err := cat.CommitTable(ctx, tbl.Identifier(), reqs,
[]table.Update{update}); err != nil {
+ output.Error(fmt.Errorf("create branch failed: %w", err))
+ os.Exit(1)
+ }
+
+ output.RefCreated(RefCreatedResult{
+ Table: tableIDString(tbl),
+ RefName: cmd.BranchName,
+ RefType: string(table.BranchRef),
+ SnapshotID: snapshotID,
+ })
+}
+
+func runTagCreate(ctx context.Context, output Output, cat catalog.Catalog, cmd
*TagCreateCmd) {
+ tbl := loadTable(ctx, output, cat, cmd.TableID)
+ meta := tbl.Metadata()
+
+ snapshotID := resolveSnapshotID(output, tbl, cmd.SnapshotID)
+
+ var maxRefAgeMs int64
+ if cmd.MaxRefAge != "" {
+ d, err := parseDuration(cmd.MaxRefAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-ref-age: %w",
err))
+ os.Exit(1)
+ }
+
+ maxRefAgeMs = d.Milliseconds()
+ }
+
+ update := table.NewSetSnapshotRefUpdate(cmd.TagName, snapshotID,
table.TagRef,
+ maxRefAgeMs, 0, 0)
+ reqs := []table.Requirement{table.AssertTableUUID(meta.TableUUID())}
+
+ if _, _, err := cat.CommitTable(ctx, tbl.Identifier(), reqs,
[]table.Update{update}); err != nil {
+ output.Error(fmt.Errorf("create tag failed: %w", err))
+ os.Exit(1)
+ }
+
+ output.RefCreated(RefCreatedResult{
+ Table: tableIDString(tbl),
+ RefName: cmd.TagName,
+ RefType: string(table.TagRef),
+ SnapshotID: snapshotID,
+ })
+}
+
+func resolveSnapshotID(output Output, tbl *table.Table, explicit *int64) int64
{
+ if explicit != nil {
+ return *explicit
Review Comment:
When `explicit != nil` the value is returned without checking it exists in
the metadata. The catalog will reject it eventually, but the resulting error is
a wrapped REST failure rather than the clear `snapshot %d not found` you'd get
pre-flight. `meta.SnapshotByID` is already used elsewhere in this file; one
extra check here is consistent with how the rollback PR (#1071) handles the
same case.
##########
cmd/iceberg/branch_tag.go:
##########
@@ -19,21 +19,135 @@ package main
import (
"context"
+ "encoding/json"
"errors"
+ "fmt"
"os"
"github.com/apache/iceberg-go/catalog"
+ "github.com/apache/iceberg-go/table"
+ "github.com/pterm/pterm"
)
-func runBranch(_ context.Context, output Output, _ catalog.Catalog, _
*BranchCmd) {
- output.Error(errors.New("branch: not yet implemented"))
- os.Exit(1)
+func runBranch(ctx context.Context, output Output, cat catalog.Catalog, cmd
*BranchCmd) {
+ switch {
+ case cmd.Create != nil:
+ runBranchCreate(ctx, output, cat, cmd.Create)
+ }
}
-func runTag(_ context.Context, output Output, _ catalog.Catalog, _ *TagCmd) {
- output.Error(errors.New("tag: not yet implemented"))
- os.Exit(1)
+func runTag(ctx context.Context, output Output, cat catalog.Catalog, cmd
*TagCmd) {
+ switch {
+ case cmd.Create != nil:
+ runTagCreate(ctx, output, cat, cmd.Create)
+ }
}
-func (textOutput) RefCreated(_ RefCreatedResult) {}
-func (jsonOutput) RefCreated(_ RefCreatedResult) {}
+func runBranchCreate(ctx context.Context, output Output, cat catalog.Catalog,
cmd *BranchCreateCmd) {
+ tbl := loadTable(ctx, output, cat, cmd.TableID)
+ meta := tbl.Metadata()
+
+ snapshotID := resolveSnapshotID(output, tbl, cmd.SnapshotID)
+
+ var maxRefAgeMs int64
+ if cmd.MaxRefAge != "" {
+ d, err := parseDuration(cmd.MaxRefAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-ref-age: %w",
err))
+ os.Exit(1)
+ }
+
+ maxRefAgeMs = d.Milliseconds()
+ }
+
+ var maxSnapshotAgeMs int64
+ if cmd.MaxSnapshotAge != "" {
+ d, err := parseDuration(cmd.MaxSnapshotAge)
+ if err != nil {
+ output.Error(fmt.Errorf("invalid --max-snapshot-age:
%w", err))
+ os.Exit(1)
+ }
+
+ maxSnapshotAgeMs = d.Milliseconds()
+ }
+
+ var minSnapshotsToKeep int
+ if cmd.MinSnapshotsToKeep != nil {
+ minSnapshotsToKeep = *cmd.MinSnapshotsToKeep
+ }
+
+ update := table.NewSetSnapshotRefUpdate(cmd.BranchName, snapshotID,
table.BranchRef,
+ maxRefAgeMs, maxSnapshotAgeMs, minSnapshotsToKeep)
+ reqs := []table.Requirement{table.AssertTableUUID(meta.TableUUID())}
+
+ if _, _, err := cat.CommitTable(ctx, tbl.Identifier(), reqs,
[]table.Update{update}); err != nil {
+ output.Error(fmt.Errorf("create branch failed: %w", err))
+ os.Exit(1)
+ }
+
+ output.RefCreated(RefCreatedResult{
+ Table: tableIDString(tbl),
+ RefName: cmd.BranchName,
+ RefType: string(table.BranchRef),
+ SnapshotID: snapshotID,
Review Comment:
`RefCreatedResult` (defined in `maintenance.go`) emits only `table`,
`ref_name`, `ref_type`, `snapshot_id` — not the retention values that were
committed. A script consuming the JSON has no way to verify what
`max_ref_age_ms`, `max_snapshot_age_ms`, `min_snapshots_to_keep` actually
landed. Echo them back in the result struct (with `omitempty` so the tag path
stays clean).
##########
cmd/iceberg/branch_tag_test.go:
##########
@@ -0,0 +1,145 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+import (
+ "bytes"
+ "os"
+ "testing"
+
+ "github.com/apache/iceberg-go/table"
+ "github.com/pterm/pterm"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+const branchTagTestMetadata = `{
+ "format-version": 2,
+ "table-uuid": "9c12d441-03fe-4693-9a96-a0705ddf69c1",
+ "location": "s3://bucket/test/location",
+ "last-sequence-number": 1,
+ "last-updated-ms": 1602638573590,
+ "last-column-id": 1,
+ "current-schema-id": 0,
+ "schemas": [
+ {"type": "struct", "schema-id": 0, "fields": [{"id": 1, "name": "x",
"required": true, "type": "long"}]}
+ ],
+ "default-spec-id": 0,
+ "partition-specs": [{"spec-id": 0, "fields": []}],
+ "last-partition-id": 0,
+ "default-sort-order-id": 0,
+ "sort-orders": [{"order-id": 0, "fields": []}],
+ "properties": {},
+ "current-snapshot-id": 5000,
+ "snapshots": [
+ {"snapshot-id": 5000, "timestamp-ms": 1615100955770,
"sequence-number": 1, "summary": {"operation": "append"}, "manifest-list":
"s3://a/b/1.avro", "schema-id": 0}
+ ],
+ "snapshot-log": [],
+ "metadata-log": [],
+ "refs": {"main": {"snapshot-id": 5000, "type": "branch"}}
+}`
+
+func TestResolveSnapshotIDExplicit(t *testing.T) {
+ meta, err := table.ParseMetadataBytes([]byte(branchTagTestMetadata))
+ require.NoError(t, err)
+
+ tbl := table.New([]string{"db", "tbl"}, meta, "", nil, nil)
+ explicit := int64(1234)
+
+ result := resolveSnapshotID(textOutput{}, tbl, &explicit)
+ assert.Equal(t, int64(1234), result)
+}
+
+func TestResolveSnapshotIDCurrent(t *testing.T) {
+ meta, err := table.ParseMetadataBytes([]byte(branchTagTestMetadata))
+ require.NoError(t, err)
+
+ tbl := table.New([]string{"db", "tbl"}, meta, "", nil, nil)
+
+ result := resolveSnapshotID(textOutput{}, tbl, nil)
+ assert.Equal(t, int64(5000), result)
+}
+
+func TestTextOutputRefCreated(t *testing.T) {
+ var buf bytes.Buffer
+ pterm.SetDefaultOutput(&buf)
+ pterm.DisableColor()
+
+ result := RefCreatedResult{
+ Table: "db.events",
+ RefName: "feature-branch",
+ RefType: "branch",
+ SnapshotID: 5000,
+ }
+
+ buf.Reset()
+ textOutput{}.RefCreated(result)
+
+ output := buf.String()
+ assert.Contains(t, output, "Created branch")
+ assert.Contains(t, output, "feature-branch")
+ assert.Contains(t, output, "db.events")
+ assert.Contains(t, output, "5000")
+}
+
+func TestTextOutputRefCreatedTag(t *testing.T) {
+ var buf bytes.Buffer
+ pterm.SetDefaultOutput(&buf)
+ pterm.DisableColor()
+
+ result := RefCreatedResult{
+ Table: "db.events",
+ RefName: "v1.0",
+ RefType: "tag",
+ SnapshotID: 3000,
+ }
+
+ buf.Reset()
+ textOutput{}.RefCreated(result)
+
+ output := buf.String()
+ assert.Contains(t, output, "Created tag")
+ assert.Contains(t, output, "v1.0")
+ assert.Contains(t, output, "3000")
+}
+
+func TestJSONOutputRefCreated(t *testing.T) {
+ oldStdout := os.Stdout
+ r, w, _ := os.Pipe()
Review Comment:
`r, w, _ := os.Pipe()` drops the error. If pipe creation fails, `w` is nil
and `os.Stdout = w` corrupts the process for subsequent tests. Suggested:
```go
r, w, err := os.Pipe()
require.NoError(t, err)
oldStdout := os.Stdout
os.Stdout = w
t.Cleanup(func() { w.Close(); os.Stdout = oldStdout })
```
##########
cmd/iceberg/branch_tag_test.go:
##########
@@ -0,0 +1,145 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+import (
+ "bytes"
+ "os"
+ "testing"
+
+ "github.com/apache/iceberg-go/table"
+ "github.com/pterm/pterm"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+const branchTagTestMetadata = `{
+ "format-version": 2,
+ "table-uuid": "9c12d441-03fe-4693-9a96-a0705ddf69c1",
+ "location": "s3://bucket/test/location",
+ "last-sequence-number": 1,
+ "last-updated-ms": 1602638573590,
+ "last-column-id": 1,
+ "current-schema-id": 0,
+ "schemas": [
+ {"type": "struct", "schema-id": 0, "fields": [{"id": 1, "name": "x",
"required": true, "type": "long"}]}
+ ],
+ "default-spec-id": 0,
+ "partition-specs": [{"spec-id": 0, "fields": []}],
+ "last-partition-id": 0,
+ "default-sort-order-id": 0,
+ "sort-orders": [{"order-id": 0, "fields": []}],
+ "properties": {},
+ "current-snapshot-id": 5000,
+ "snapshots": [
+ {"snapshot-id": 5000, "timestamp-ms": 1615100955770,
"sequence-number": 1, "summary": {"operation": "append"}, "manifest-list":
"s3://a/b/1.avro", "schema-id": 0}
+ ],
+ "snapshot-log": [],
+ "metadata-log": [],
+ "refs": {"main": {"snapshot-id": 5000, "type": "branch"}}
+}`
+
+func TestResolveSnapshotIDExplicit(t *testing.T) {
+ meta, err := table.ParseMetadataBytes([]byte(branchTagTestMetadata))
+ require.NoError(t, err)
+
+ tbl := table.New([]string{"db", "tbl"}, meta, "", nil, nil)
+ explicit := int64(1234)
+
+ result := resolveSnapshotID(textOutput{}, tbl, &explicit)
+ assert.Equal(t, int64(1234), result)
+}
+
+func TestResolveSnapshotIDCurrent(t *testing.T) {
+ meta, err := table.ParseMetadataBytes([]byte(branchTagTestMetadata))
+ require.NoError(t, err)
+
+ tbl := table.New([]string{"db", "tbl"}, meta, "", nil, nil)
+
+ result := resolveSnapshotID(textOutput{}, tbl, nil)
+ assert.Equal(t, int64(5000), result)
+}
+
+func TestTextOutputRefCreated(t *testing.T) {
+ var buf bytes.Buffer
+ pterm.SetDefaultOutput(&buf)
Review Comment:
`pterm.SetDefaultOutput(&buf)` mutates package-global state without restore
(same at line 102). Sequential today, data-race on parallel tomorrow. Add
`t.Cleanup(func() { pterm.SetDefaultOutput(os.Stderr); pterm.EnableColor() })`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]