From 6f65eaac0835fa9226ee78092415afd14895fecb Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Tue, 3 Mar 2026 08:53:01 -0500 Subject: [PATCH] refactor(identity): remove duplication identity.Interface mocks --- entities/identity/identity_test.go | 34 ++++++++-------- entities/identity/key_test.go | 22 ----------- entities/identity/version_test.go | 63 +----------------------------- 3 files changed, 18 insertions(+), 101 deletions(-) diff --git a/entities/identity/identity_test.go b/entities/identity/identity_test.go index c74b66894fd7da70d49fbd624134596569efc0e4..8ff4c86ac2bb4306395b924b17798953ebc13c92 100644 --- a/entities/identity/identity_test.go +++ b/entities/identity/identity_test.go @@ -13,65 +13,65 @@ import ( "github.com/git-bug/git-bug/util/timestamp" ) -type testIdentityMock struct { +type mockIdentity struct { name string login string email string } -func (m *testIdentityMock) Name() string { +func (m *mockIdentity) Name() string { return m.name } -func (m *testIdentityMock) Login() string { +func (m *mockIdentity) Login() string { return m.login } -func (m *testIdentityMock) Email() string { +func (m *mockIdentity) Email() string { return m.email } -func (m *testIdentityMock) DisplayName() string { +func (m *mockIdentity) DisplayName() string { return m.name } -func (m *testIdentityMock) AvatarUrl() string { +func (m *mockIdentity) AvatarUrl() string { return "" } -func (m *testIdentityMock) Keys() []*Key { +func (m *mockIdentity) Keys() []*Key { return nil } -func (m *testIdentityMock) SigningKey(repo repository.RepoKeyring) (*Key, error) { +func (m *mockIdentity) SigningKey(repo repository.RepoKeyring) (*Key, error) { return nil, nil } -func (m *testIdentityMock) ValidKeysAtTime(clockName string, time lamport.Time) []*Key { +func (m *mockIdentity) ValidKeysAtTime(clockName string, time lamport.Time) []*Key { return nil } -func (m *testIdentityMock) LastModification() timestamp.Timestamp { +func (m *mockIdentity) LastModification() timestamp.Timestamp { return 0 } -func (m *testIdentityMock) LastModificationLamports() map[string]lamport.Time { +func (m *mockIdentity) LastModificationLamports() map[string]lamport.Time { return nil } -func (m *testIdentityMock) IsProtected() bool { +func (m *mockIdentity) IsProtected() bool { return false } -func (m *testIdentityMock) Validate() error { +func (m *mockIdentity) Validate() error { return nil } -func (m *testIdentityMock) NeedCommit() bool { +func (m *mockIdentity) NeedCommit() bool { return false } -func (m *testIdentityMock) Id() entity.Id { +func (m *mockIdentity) Id() entity.Id { return "" } @@ -202,7 +202,7 @@ func TestIdentityCommitLoad(t *testing.T) { require.True(t, identitiesEqual(identity, loaded), "loaded identity should equal original (comparing by key fingerprint)") // multiple versions - testIdentity := &testIdentityMock{name: "René Descartes", email: "rene.descartes@example.com"} + testIdentity := &mockIdentity{name: "René Descartes", email: "rene.descartes@example.com"} identity, err = NewIdentityFull(repo, "René Descartes", "rene.descartes@example.com", "", "", []*Key{generatePublicKey(testIdentity)}) require.NoError(t, err) @@ -290,7 +290,7 @@ func commitsAreSet(t *testing.T, identity *Identity) { // Test that the correct crypto keys are returned for a given lamport time func TestIdentity_ValidKeysAtTime(t *testing.T) { - testIdentity := &testIdentityMock{name: "Test User", email: "test@example.com"} + testIdentity := &mockIdentity{name: "Test User", email: "test@example.com"} pubKeyA := generatePublicKey(testIdentity) pubKeyB := generatePublicKey(testIdentity) pubKeyC := generatePublicKey(testIdentity) diff --git a/entities/identity/key_test.go b/entities/identity/key_test.go index 09cbc3651fe0b3ba001ead56276d90f96b75f35b..08ae8201d57f85d3ff3a18cc7d293dc9bdae862b 100644 --- a/entities/identity/key_test.go +++ b/entities/identity/key_test.go @@ -8,32 +8,10 @@ import ( "github.com/stretchr/testify/require" - "github.com/git-bug/git-bug/entity" "github.com/git-bug/git-bug/repository" - "github.com/git-bug/git-bug/util/lamport" - "github.com/git-bug/git-bug/util/timestamp" ) -type mockIdentity struct { - name string - login string - email string -} -func (m *mockIdentity) Name() string { return m.name } -func (m *mockIdentity) Login() string { return m.login } -func (m *mockIdentity) Email() string { return m.email } -func (m *mockIdentity) DisplayName() string { return m.name } -func (m *mockIdentity) AvatarUrl() string { return "" } -func (m *mockIdentity) Keys() []*Key { return nil } -func (m *mockIdentity) SigningKey(repo repository.RepoKeyring) (*Key, error) { return nil, nil } -func (m *mockIdentity) ValidKeysAtTime(clockName string, time lamport.Time) []*Key { return nil } -func (m *mockIdentity) LastModification() timestamp.Timestamp { return 0 } -func (m *mockIdentity) LastModificationLamports() map[string]lamport.Time { return nil } -func (m *mockIdentity) IsProtected() bool { return false } -func (m *mockIdentity) Validate() error { return nil } -func (m *mockIdentity) NeedCommit() bool { return false } -func (m *mockIdentity) Id() entity.Id { return "" } func TestPublicKeyJSON(t *testing.T) { id := &mockIdentity{name: "John Smith", email: "jsmith@example.com"} diff --git a/entities/identity/version_test.go b/entities/identity/version_test.go index 9748838e1f6763de35c8c4a02ba7e506a08f6450..48ed48f0d556516e05863b5dda5999c96f0671f5 100644 --- a/entities/identity/version_test.go +++ b/entities/identity/version_test.go @@ -11,70 +11,9 @@ import ( "github.com/git-bug/git-bug/entity" "github.com/git-bug/git-bug/repository" "github.com/git-bug/git-bug/util/lamport" - "github.com/git-bug/git-bug/util/timestamp" ) -type testVersionMockIdentity struct { - name string - login string - email string -} - -func (m *testVersionMockIdentity) Name() string { - return m.name -} - -func (m *testVersionMockIdentity) Login() string { - return m.login -} - -func (m *testVersionMockIdentity) Email() string { - return m.email -} - -func (m *testVersionMockIdentity) DisplayName() string { - return m.name -} - -func (m *testVersionMockIdentity) AvatarUrl() string { - return "" -} - -func (m *testVersionMockIdentity) Keys() []*Key { - return nil -} - -func (m *testVersionMockIdentity) SigningKey(repo repository.RepoKeyring) (*Key, error) { - return nil, nil -} - -func (m *testVersionMockIdentity) ValidKeysAtTime(clockName string, time lamport.Time) []*Key { - return nil -} - -func (m *testVersionMockIdentity) LastModification() timestamp.Timestamp { - return 0 -} - -func (m *testVersionMockIdentity) LastModificationLamports() map[string]lamport.Time { - return nil -} -func (m *testVersionMockIdentity) IsProtected() bool { - return false -} - -func (m *testVersionMockIdentity) Validate() error { - return nil -} - -func (m *testVersionMockIdentity) NeedCommit() bool { - return false -} - -func (m *testVersionMockIdentity) Id() entity.Id { - return "" -} func makeIdentityTestRepo(t *testing.T) repository.ClockedRepo { repo := repository.NewMockRepo() @@ -95,7 +34,7 @@ func makeIdentityTestRepo(t *testing.T) repository.ClockedRepo { func TestVersionJSON(t *testing.T) { repo := makeIdentityTestRepo(t) - testIdentity := &testVersionMockIdentity{name: "name", email: "email", login: "login"} + testIdentity := &mockIdentity{name: "name", email: "email", login: "login"} keys := []*Key{ generatePublicKey(testIdentity), generatePublicKey(testIdentity),