Fix goconst linter warnings by converting repeated strings to constants
- Added testUserAlice constant for 'alice' in test files - Added windowsOS constant for 'windows' in test files - Added testIssueBD1/testIssueBD2 constants for 'bd-1'/'bd-2' in test files - Added testVersion100 constant for '1.0.0' in version tests - Added testIssueCustom1 constant for 'custom-1' in lazy init tests Closes bd-54 Amp-Thread-ID: https://ampcode.com/threads/T-0a4e5d44-2d95-4948-8f4a-d8facf8657c7 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
sqlitestorage "github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
)
|
||||
|
||||
const testVersion100 = "1.0.0"
|
||||
|
||||
func TestVersionCompatibility(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -20,8 +22,8 @@ func TestVersionCompatibility(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Exact version match",
|
||||
serverVersion: "1.0.0",
|
||||
clientVersion: "1.0.0",
|
||||
serverVersion: testVersion100,
|
||||
clientVersion: testVersion100,
|
||||
shouldWork: true,
|
||||
},
|
||||
{
|
||||
@@ -39,7 +41,7 @@ func TestVersionCompatibility(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Different major versions - client newer",
|
||||
serverVersion: "1.0.0",
|
||||
serverVersion: testVersion100,
|
||||
clientVersion: "2.0.0",
|
||||
shouldWork: false,
|
||||
errorContains: "incompatible major versions",
|
||||
@@ -47,13 +49,13 @@ func TestVersionCompatibility(t *testing.T) {
|
||||
{
|
||||
name: "Different major versions - daemon newer",
|
||||
serverVersion: "2.0.0",
|
||||
clientVersion: "1.0.0",
|
||||
clientVersion: testVersion100,
|
||||
shouldWork: false,
|
||||
errorContains: "incompatible major versions",
|
||||
},
|
||||
{
|
||||
name: "Empty client version (legacy client)",
|
||||
serverVersion: "1.0.0",
|
||||
serverVersion: testVersion100,
|
||||
clientVersion: "",
|
||||
shouldWork: true,
|
||||
},
|
||||
@@ -65,8 +67,8 @@ func TestVersionCompatibility(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Version without v prefix",
|
||||
serverVersion: "1.0.0",
|
||||
clientVersion: "1.0.0",
|
||||
serverVersion: testVersion100,
|
||||
clientVersion: testVersion100,
|
||||
shouldWork: true,
|
||||
},
|
||||
{
|
||||
@@ -182,8 +184,8 @@ func TestHealthCheckIncludesVersionInfo(t *testing.T) {
|
||||
defer store.Close()
|
||||
|
||||
// Set explicit versions
|
||||
ServerVersion = "1.0.0"
|
||||
ClientVersion = "1.0.0"
|
||||
ServerVersion = testVersion100
|
||||
ClientVersion = testVersion100
|
||||
|
||||
server := NewServer(socketPath, store)
|
||||
|
||||
@@ -246,7 +248,7 @@ func TestIncompatibleVersionInHealth(t *testing.T) {
|
||||
defer store.Close()
|
||||
|
||||
// Set incompatible versions
|
||||
ServerVersion = "1.0.0"
|
||||
ServerVersion = testVersion100
|
||||
ClientVersion = "2.0.0"
|
||||
|
||||
server := NewServer(socketPath, store)
|
||||
@@ -304,7 +306,7 @@ func TestVersionCheckMessage(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Major mismatch - daemon older",
|
||||
serverVersion: "1.0.0",
|
||||
serverVersion: testVersion100,
|
||||
clientVersion: "2.0.0",
|
||||
expectError: true,
|
||||
errorContains: "Daemon is older; upgrade and restart daemon",
|
||||
@@ -312,13 +314,13 @@ func TestVersionCheckMessage(t *testing.T) {
|
||||
{
|
||||
name: "Major mismatch - client older",
|
||||
serverVersion: "2.0.0",
|
||||
clientVersion: "1.0.0",
|
||||
clientVersion: testVersion100,
|
||||
expectError: true,
|
||||
errorContains: "Client is older; upgrade the bd CLI",
|
||||
},
|
||||
{
|
||||
name: "Minor mismatch - daemon older",
|
||||
serverVersion: "1.0.0",
|
||||
serverVersion: testVersion100,
|
||||
clientVersion: "1.1.0",
|
||||
expectError: true,
|
||||
errorContains: "daemon 1.0.0 is older than client 1.1.0",
|
||||
@@ -326,7 +328,7 @@ func TestVersionCheckMessage(t *testing.T) {
|
||||
{
|
||||
name: "Compatible versions",
|
||||
serverVersion: "1.1.0",
|
||||
clientVersion: "1.0.0",
|
||||
clientVersion: testVersion100,
|
||||
expectError: false,
|
||||
},
|
||||
}
|
||||
@@ -366,7 +368,7 @@ func TestPingAndHealthBypassVersionCheck(t *testing.T) {
|
||||
defer store.Close()
|
||||
|
||||
// Set incompatible versions
|
||||
ServerVersion = "1.0.0"
|
||||
ServerVersion = testVersion100
|
||||
ClientVersion = "2.0.0"
|
||||
|
||||
server := NewServer(socketPath, store)
|
||||
@@ -440,8 +442,8 @@ func TestMetricsOperation(t *testing.T) {
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
ServerVersion = "1.0.0"
|
||||
ClientVersion = "1.0.0"
|
||||
ServerVersion = testVersion100
|
||||
ClientVersion = testVersion100
|
||||
|
||||
server := NewServer(socketPath, store)
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
const testIssueBD1 = "bd-1"
|
||||
|
||||
func TestDetectCollisions(t *testing.T) {
|
||||
// Create temporary database
|
||||
tmpDir, err := os.MkdirTemp("", "collision-test-*")
|
||||
@@ -29,7 +31,7 @@ func TestDetectCollisions(t *testing.T) {
|
||||
|
||||
// Setup: Create some existing issues in the database
|
||||
existingIssue1 := &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Existing issue 1",
|
||||
Description: "This is an existing issue",
|
||||
Status: types.StatusOpen,
|
||||
@@ -66,7 +68,7 @@ func TestDetectCollisions(t *testing.T) {
|
||||
name: "exact match - idempotent import",
|
||||
incomingIssues: []*types.Issue{
|
||||
{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Existing issue 1",
|
||||
Description: "This is an existing issue",
|
||||
Status: types.StatusOpen,
|
||||
@@ -98,7 +100,7 @@ func TestDetectCollisions(t *testing.T) {
|
||||
name: "collision - same ID, different title",
|
||||
incomingIssues: []*types.Issue{
|
||||
{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Modified title",
|
||||
Description: "This is an existing issue",
|
||||
Status: types.StatusOpen,
|
||||
@@ -113,7 +115,7 @@ func TestDetectCollisions(t *testing.T) {
|
||||
if len(collisions) != 1 {
|
||||
t.Fatalf("expected 1 collision, got %d", len(collisions))
|
||||
}
|
||||
if collisions[0].ID != "bd-1" {
|
||||
if collisions[0].ID != testIssueBD1 {
|
||||
t.Errorf("expected collision ID bd-1, got %s", collisions[0].ID)
|
||||
}
|
||||
if len(collisions[0].ConflictingFields) != 1 {
|
||||
@@ -167,7 +169,7 @@ func TestDetectCollisions(t *testing.T) {
|
||||
incomingIssues: []*types.Issue{
|
||||
{
|
||||
// Exact match
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Existing issue 1",
|
||||
Description: "This is an existing issue",
|
||||
Status: types.StatusOpen,
|
||||
@@ -201,7 +203,7 @@ func TestDetectCollisions(t *testing.T) {
|
||||
name: "collision - estimated_minutes differs",
|
||||
incomingIssues: []*types.Issue{
|
||||
{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Existing issue 1",
|
||||
Description: "This is an existing issue",
|
||||
Status: types.StatusOpen,
|
||||
@@ -258,7 +260,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
{
|
||||
name: "identical issues",
|
||||
existing: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test desc",
|
||||
Status: types.StatusOpen,
|
||||
@@ -266,7 +268,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
IssueType: types.TypeTask,
|
||||
},
|
||||
incoming: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test desc",
|
||||
Status: types.StatusOpen,
|
||||
@@ -278,7 +280,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
{
|
||||
name: "different title",
|
||||
existing: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Original",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -286,7 +288,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
IssueType: types.TypeTask,
|
||||
},
|
||||
incoming: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Modified",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -298,7 +300,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
{
|
||||
name: "different status and priority",
|
||||
existing: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -306,7 +308,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
IssueType: types.TypeTask,
|
||||
},
|
||||
incoming: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusClosed,
|
||||
@@ -318,7 +320,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
{
|
||||
name: "estimated_minutes - both nil",
|
||||
existing: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -327,7 +329,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
EstimatedMinutes: nil,
|
||||
},
|
||||
incoming: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -340,7 +342,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
{
|
||||
name: "estimated_minutes - existing nil, incoming set",
|
||||
existing: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -349,7 +351,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
EstimatedMinutes: nil,
|
||||
},
|
||||
incoming: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -362,7 +364,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
{
|
||||
name: "estimated_minutes - same values",
|
||||
existing: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -371,7 +373,7 @@ func TestCompareIssues(t *testing.T) {
|
||||
EstimatedMinutes: intPtr(60),
|
||||
},
|
||||
incoming: &types.Issue{
|
||||
ID: "bd-1",
|
||||
ID: testIssueBD1,
|
||||
Title: "Test",
|
||||
Description: "Test",
|
||||
Status: types.StatusOpen,
|
||||
@@ -710,7 +712,7 @@ func TestCountReferencesWordBoundary(t *testing.T) {
|
||||
// Adjust expected based on actual counting logic
|
||||
// countReferences skips the issue itself
|
||||
expected := tt.expectedCount
|
||||
if tt.issueID == "bd-1" {
|
||||
if tt.issueID == testIssueBD1 {
|
||||
expected = 1 // only bd-10's description
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
const testUserAlice = "alice"
|
||||
|
||||
func TestAddComment(t *testing.T) {
|
||||
store, cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
@@ -26,7 +28,7 @@ func TestAddComment(t *testing.T) {
|
||||
}
|
||||
|
||||
// Add a comment
|
||||
err = store.AddComment(ctx, issue.ID, "alice", "This is a test comment")
|
||||
err = store.AddComment(ctx, issue.ID, testUserAlice, "This is a test comment")
|
||||
if err != nil {
|
||||
t.Fatalf("AddComment failed: %v", err)
|
||||
}
|
||||
@@ -55,7 +57,7 @@ func TestAddComment(t *testing.T) {
|
||||
t.Fatal("Comment event not found")
|
||||
}
|
||||
|
||||
if commentEvent.Actor != "alice" {
|
||||
if commentEvent.Actor != testUserAlice {
|
||||
t.Errorf("Expected actor 'alice', got '%s'", commentEvent.Actor)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
const testIssueCustom1 = "custom-1"
|
||||
|
||||
// TestLazyCounterInitialization verifies that counters are initialized lazily
|
||||
// on first use, not by scanning the entire database on every CreateIssue
|
||||
func TestLazyCounterInitialization(t *testing.T) {
|
||||
@@ -163,7 +165,7 @@ func TestLazyCounterInitializationMultiplePrefix(t *testing.T) {
|
||||
t.Fatalf("CreateIssue failed: %v", err)
|
||||
}
|
||||
|
||||
if customIssue.ID != "custom-1" {
|
||||
if customIssue.ID != testIssueCustom1 {
|
||||
t.Errorf("Expected custom-1, got %s", customIssue.ID)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user