Skip to content

Handle empty metadata in import #7364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/graveler/graveler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2907,6 +2907,9 @@ func (g *Graveler) Import(ctx context.Context, repository *RepositoryRecord, des
commit.Parents = []CommitID{toCommit.CommitID}
commit.Generation = toCommit.Generation + 1
commit.Metadata = commitParams.Metadata
if commit.Metadata == nil {
commit.Metadata = make(Metadata)
}
commit.Metadata[MergeStrategyMetadataKey] = MergeStrategySrcWinsStr
preRunID = g.hooks.NewRunID()
err = g.hooks.PreCommitHook(ctx, HookRecord{
Expand Down
12 changes: 10 additions & 2 deletions pkg/graveler/graveler_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func TestGravelerImport(t *testing.T) {
}}))
}

t.Run("import successful", func(t *testing.T) {
importTest := func(t *testing.T, metadata graveler.Metadata) {
test := testutil.InitGravelerTest(t)
firstUpdateBranch(test)
emptyStagingTokenCombo(test, 2)
Expand Down Expand Up @@ -672,9 +672,17 @@ func TestGravelerImport(t *testing.T) {
test.StagingManager.EXPECT().DropAsync(ctx, stagingToken3).Times(1)
test.RefManager.EXPECT().SetRepositoryMetadata(ctx, repository, gomock.Any())

val, err := test.Sut.Import(ctx, repository, branch1ID, commit2.MetaRangeID, graveler.CommitParams{Metadata: graveler.Metadata{}}, nil)
val, err := test.Sut.Import(ctx, repository, branch1ID, commit2.MetaRangeID, graveler.CommitParams{Metadata: metadata}, nil)
require.NoError(t, err)
require.NotNil(t, val)
require.Equal(t, commit4ID, graveler.CommitID(val.Ref()))
}

t.Run("import successful without metadata", func(t *testing.T) {
importTest(t, nil)
})

t.Run("import successful with metadata", func(t *testing.T) {
importTest(t, graveler.Metadata{"key": "value"})
})
}