|
|
|
@@ -695,7 +695,7 @@ func TestGitRepository_Read(t *testing.T) {
|
|
|
|
|
Hash: hash.Hash{},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{
|
|
|
|
|
Tree: hash.Hash([]byte("tree-hash")),
|
|
|
|
|
Tree: hash.MustFromHex("abcdef1234567890abcdef1234567890abcdef12"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetTreeByPathReturns(&nanogit.Tree{
|
|
|
|
|
Hash: hash.Hash{},
|
|
|
|
@@ -1191,7 +1191,7 @@ func TestGitRepository_LatestRef(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3}, // Non-empty hash
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, // Non-empty hash
|
|
|
|
|
}, nil)
|
|
|
|
|
},
|
|
|
|
|
gitConfig: RepositoryConfig{
|
|
|
|
@@ -1412,11 +1412,11 @@ func TestGitRepository_CompareFiles(t *testing.T) {
|
|
|
|
|
// Return refs for base and ref
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
// Return comparison results
|
|
|
|
@@ -1449,11 +1449,11 @@ func TestGitRepository_CompareFiles(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
mockClient.CompareCommitsReturns([]nanogit.CommitFile{}, nil)
|
|
|
|
@@ -1547,7 +1547,7 @@ func TestGitRepository_ensureBranchExists(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
},
|
|
|
|
|
gitConfig: RepositoryConfig{
|
|
|
|
@@ -1565,7 +1565,7 @@ func TestGitRepository_ensureBranchExists(t *testing.T) {
|
|
|
|
|
// Second call - get source branch
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
// CreateRef succeeds
|
|
|
|
|
mockClient.CreateRefReturns(nil)
|
|
|
|
@@ -1862,7 +1862,7 @@ func TestGitRepository_resolveRefToHash(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
},
|
|
|
|
|
gitConfig: RepositoryConfig{
|
|
|
|
@@ -1887,7 +1887,7 @@ func TestGitRepository_resolveRefToHash(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
},
|
|
|
|
|
gitConfig: RepositoryConfig{
|
|
|
|
@@ -1939,7 +1939,7 @@ func TestGitRepository_resolveRefToHash(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
if tt.wantError {
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
require.Nil(t, refHash)
|
|
|
|
|
require.Equal(t, hash.Zero, refHash)
|
|
|
|
|
} else {
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.NotNil(t, refHash)
|
|
|
|
@@ -2212,7 +2212,7 @@ func TestGitRepository_EdgeCases(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
@@ -2251,7 +2251,7 @@ func TestGitRepository_EdgeCases(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{Tree: hash.Hash{}}, nil)
|
|
|
|
|
mockClient.GetBlobByPathReturns(&nanogit.Blob{}, errors.New("some read error"))
|
|
|
|
@@ -2401,7 +2401,7 @@ func TestGitRepository_ResolveRefToHash_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/invalid-hex",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
},
|
|
|
|
|
ref: "invalid-hex-zzz",
|
|
|
|
@@ -2412,7 +2412,7 @@ func TestGitRepository_ResolveRefToHash_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
},
|
|
|
|
|
ref: "refs/heads/feature",
|
|
|
|
@@ -2423,7 +2423,7 @@ func TestGitRepository_ResolveRefToHash_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/tags/v1.0.0",
|
|
|
|
|
Hash: hash.Hash{7, 8, 9},
|
|
|
|
|
Hash: hash.Hash{7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
|
|
|
|
|
}, nil)
|
|
|
|
|
},
|
|
|
|
|
ref: "refs/tags/v1.0.0",
|
|
|
|
@@ -2540,11 +2540,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.CompareCommitsReturns(nil, errors.New("compare error"))
|
|
|
|
|
},
|
|
|
|
@@ -2558,11 +2558,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.CompareCommitsReturns([]nanogit.CommitFile{
|
|
|
|
|
{
|
|
|
|
@@ -2580,11 +2580,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.CompareCommitsReturns([]nanogit.CommitFile{
|
|
|
|
|
{
|
|
|
|
@@ -2606,11 +2606,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.CompareCommitsReturns([]nanogit.CommitFile{
|
|
|
|
|
{
|
|
|
|
@@ -2683,7 +2683,7 @@ func TestGitRepository_ReadTree_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetFlatTreeReturns(nil, errors.New("flat tree error"))
|
|
|
|
|
},
|
|
|
|
@@ -2694,23 +2694,23 @@ func TestGitRepository_ReadTree_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetFlatTreeReturns(&nanogit.FlatTree{
|
|
|
|
|
Entries: []nanogit.FlatTreeEntry{
|
|
|
|
|
{
|
|
|
|
|
Path: "other/file.yaml", // Outside configs/
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
Type: protocol.ObjectTypeBlob,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Path: "configs/included.yaml", // Inside configs/
|
|
|
|
|
Hash: hash.Hash{7, 8, 9},
|
|
|
|
|
Hash: hash.Hash{7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26},
|
|
|
|
|
Type: protocol.ObjectTypeBlob,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Path: "configs/dir", // Directory without trailing slash
|
|
|
|
|
Hash: hash.Hash{10, 11, 12},
|
|
|
|
|
Hash: hash.Hash{10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29},
|
|
|
|
|
Type: protocol.ObjectTypeTree,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -2828,7 +2828,7 @@ func TestGitRepository_ensureBranchExists_ErrorConditions(t *testing.T) {
|
|
|
|
|
// Second call - get source branch
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
// CreateRef fails
|
|
|
|
|
mockClient.CreateRefReturns(errors.New("create ref failed"))
|
|
|
|
@@ -2880,10 +2880,10 @@ func TestGitRepository_Read_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121315"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{
|
|
|
|
|
Tree: hash.Hash([]byte("tree-hash")),
|
|
|
|
|
Tree: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetTreeByPathReturns(nil, errors.New("tree error"))
|
|
|
|
|
},
|
|
|
|
@@ -2895,7 +2895,7 @@ func TestGitRepository_Read_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(nil, errors.New("commit error"))
|
|
|
|
|
},
|
|
|
|
@@ -2907,10 +2907,10 @@ func TestGitRepository_Read_EdgeCases(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{
|
|
|
|
|
Tree: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708092a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetBlobByPathReturns(nil, errors.New("blob error"))
|
|
|
|
|
},
|
|
|
|
@@ -2965,7 +2965,7 @@ func TestGitRepository_Create_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.NewStagedWriterReturns(nil, errors.New("staged writer error"))
|
|
|
|
|
},
|
|
|
|
@@ -2977,7 +2977,7 @@ func TestGitRepository_Create_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
|
mockWriter.CreateBlobReturns(hash.Hash{}, errors.New("create blob error"))
|
|
|
|
@@ -3030,7 +3030,7 @@ func TestGitRepository_Update_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.NewStagedWriterReturns(nil, errors.New("staged writer error"))
|
|
|
|
|
},
|
|
|
|
@@ -3042,7 +3042,7 @@ func TestGitRepository_Update_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
|
mockWriter.UpdateBlobReturns(hash.Hash{}, errors.New("update blob error"))
|
|
|
|
@@ -3096,7 +3096,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.NewStagedWriterReturns(nil, errors.New("staged writer error"))
|
|
|
|
|
},
|
|
|
|
@@ -3109,7 +3109,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
|
mockWriter.DeleteBlobReturns(hash.Hash{}, errors.New("delete blob error"))
|
|
|
|
@@ -3124,7 +3124,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
|
mockWriter.DeleteTreeReturns(hash.Hash{}, errors.New("delete tree error"))
|
|
|
|
@@ -3139,7 +3139,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) {
|
|
|
|
|
setupMock: func(mockClient *mocks.FakeClient) {
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
|
mockWriter.DeleteTreeReturns(hash.Hash{}, nanogit.ErrObjectNotFound)
|
|
|
|
@@ -3186,7 +3186,7 @@ func TestGitRepository_CompareFiles_EmptyBase(t *testing.T) {
|
|
|
|
|
// Only setup for ref resolution
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.CompareCommitsReturns([]nanogit.CommitFile{
|
|
|
|
|
{
|
|
|
|
@@ -3218,8 +3218,8 @@ func TestGitRepository_CompareFiles_EmptyBase(t *testing.T) {
|
|
|
|
|
// Verify CompareCommits was called with empty base hash and feature hash
|
|
|
|
|
require.Equal(t, 1, mockClient.CompareCommitsCallCount())
|
|
|
|
|
_, baseHash, refHash := mockClient.CompareCommitsArgsForCall(0)
|
|
|
|
|
require.Nil(t, baseHash) // Empty hash for empty base
|
|
|
|
|
require.Equal(t, hash.Hash{4, 5, 6}, refHash)
|
|
|
|
|
require.Equal(t, hash.Zero, baseHash) // Empty hash for empty base
|
|
|
|
|
require.Equal(t, hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), refHash)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGitRepository_EmptyRefHandling(t *testing.T) {
|
|
|
|
@@ -3237,7 +3237,7 @@ func TestGitRepository_EmptyRefHandling(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
@@ -3299,7 +3299,7 @@ func TestGitRepository_CompareFiles_ResolveErrors(t *testing.T) {
|
|
|
|
|
// First call succeeds for base
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
// Second call fails for ref
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{}, errors.New("ref error"))
|
|
|
|
@@ -3341,14 +3341,14 @@ func TestGitRepository_Read_EmptyRef(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{
|
|
|
|
|
Tree: hash.Hash{4, 5, 6},
|
|
|
|
|
Tree: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetBlobByPathReturns(&nanogit.Blob{
|
|
|
|
|
Content: []byte("file content"),
|
|
|
|
|
Hash: hash.Hash{7, 8, 9},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
gitRepo := &gitRepository{
|
|
|
|
@@ -3376,13 +3376,13 @@ func TestGitRepository_ReadTree_EmptyRef(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetFlatTreeReturns(&nanogit.FlatTree{
|
|
|
|
|
Entries: []nanogit.FlatTreeEntry{
|
|
|
|
|
{
|
|
|
|
|
Path: "configs/test.yaml",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
Type: protocol.ObjectTypeBlob,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@@ -3504,17 +3504,17 @@ func TestGitRepository_Write_DefaultRef(t *testing.T) {
|
|
|
|
|
// First call for Read check - file not found
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{
|
|
|
|
|
Tree: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetBlobByPathReturns(&nanogit.Blob{}, nanogit.ErrObjectNotFound)
|
|
|
|
|
|
|
|
|
|
// Second call for Create
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockWriter := &mocks.FakeStagedWriter{}
|
|
|
|
|
mockWriter.CreateBlobReturns(hash.Hash{}, nil)
|
|
|
|
@@ -3545,14 +3545,14 @@ func TestGitRepository_Read_RefInFileInfo(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{
|
|
|
|
|
Tree: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetBlobByPathReturns(&nanogit.Blob{
|
|
|
|
|
Content: []byte("file content"),
|
|
|
|
|
Hash: hash.Hash{7, 8, 9},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
gitRepo := &gitRepository{
|
|
|
|
@@ -3582,10 +3582,10 @@ func TestGitRepository_Read_GetTreeByPath_NotFound(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetCommitReturns(&nanogit.Commit{
|
|
|
|
|
Tree: hash.Hash([]byte("tree-hash")),
|
|
|
|
|
Tree: hash.Hash{30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49},
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetTreeByPathReturns(nil, nanogit.ErrObjectNotFound)
|
|
|
|
|
|
|
|
|
@@ -3614,7 +3614,7 @@ func TestGitRepository_ReadTree_GetFlatTree_NotFound(t *testing.T) {
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturns(nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetFlatTreeReturns(nil, nanogit.ErrObjectNotFound)
|
|
|
|
|
|
|
|
|
@@ -3655,11 +3655,11 @@ func TestGitRepository_CompareFiles_FilesOutsideConfiguredPath_AllStatuses(t *te
|
|
|
|
|
mockClient := &mocks.FakeClient{}
|
|
|
|
|
mockClient.GetRefReturnsOnCall(0, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/main",
|
|
|
|
|
Hash: hash.Hash{1, 2, 3},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.GetRefReturnsOnCall(1, nanogit.Ref{
|
|
|
|
|
Name: "refs/heads/feature",
|
|
|
|
|
Hash: hash.Hash{4, 5, 6},
|
|
|
|
|
Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121315"),
|
|
|
|
|
}, nil)
|
|
|
|
|
mockClient.CompareCommitsReturns([]nanogit.CommitFile{
|
|
|
|
|
{
|
|
|
|
|