Consolidate tests that had a lot in common
This commit is contained in:
@@ -72,54 +72,92 @@ func TestParseInstruction(t *testing.T) {
|
||||
err := os.WriteFile(srcFile, []byte("test content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Run("Basic instruction", func(t *testing.T) {
|
||||
instruction, err := ParseInstruction("src.txt,dst.txt", testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, instruction.Source, "src.txt")
|
||||
assert.Contains(t, instruction.Target, "dst.txt")
|
||||
assert.False(t, instruction.Force)
|
||||
assert.False(t, instruction.Hard)
|
||||
assert.False(t, instruction.Delete)
|
||||
})
|
||||
// Parameterized test cases
|
||||
testCases := []struct {
|
||||
name string
|
||||
input string
|
||||
expectError bool
|
||||
errorMsg string
|
||||
assertions func(*testing.T, LinkInstruction)
|
||||
}{
|
||||
{
|
||||
name: "Basic instruction",
|
||||
input: "src.txt,dst.txt",
|
||||
expectError: false,
|
||||
assertions: func(t *testing.T, instruction LinkInstruction) {
|
||||
assert.Contains(t, instruction.Source, "src.txt")
|
||||
assert.Contains(t, instruction.Target, "dst.txt")
|
||||
assert.False(t, instruction.Force)
|
||||
assert.False(t, instruction.Hard)
|
||||
assert.False(t, instruction.Delete)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Instruction with force flag",
|
||||
input: "src.txt,dst.txt,force=true",
|
||||
expectError: false,
|
||||
assertions: func(t *testing.T, instruction LinkInstruction) {
|
||||
assert.True(t, instruction.Force)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Instruction with hard flag",
|
||||
input: "src.txt,dst.txt,hard=true",
|
||||
expectError: false,
|
||||
assertions: func(t *testing.T, instruction LinkInstruction) {
|
||||
assert.True(t, instruction.Hard)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Instruction with delete flag",
|
||||
input: "src.txt,dst.txt,delete=true",
|
||||
expectError: false,
|
||||
assertions: func(t *testing.T, instruction LinkInstruction) {
|
||||
assert.True(t, instruction.Delete)
|
||||
assert.True(t, instruction.Force) // Delete implies Force
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Legacy format",
|
||||
input: "src.txt,dst.txt,true,false,true",
|
||||
expectError: false,
|
||||
assertions: func(t *testing.T, instruction LinkInstruction) {
|
||||
assert.True(t, instruction.Force)
|
||||
assert.False(t, instruction.Hard)
|
||||
assert.True(t, instruction.Delete)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Comment line",
|
||||
input: "# This is a comment",
|
||||
expectError: true,
|
||||
errorMsg: "comment line",
|
||||
},
|
||||
{
|
||||
name: "Invalid format",
|
||||
input: "src.txt",
|
||||
expectError: true,
|
||||
errorMsg: "not enough parameters",
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("Instruction with force flag", func(t *testing.T) {
|
||||
instruction, err := ParseInstruction("src.txt,dst.txt,force=true", testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, instruction.Force)
|
||||
})
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
instruction, err := ParseInstruction(tc.input, testDir)
|
||||
|
||||
t.Run("Instruction with hard flag", func(t *testing.T) {
|
||||
instruction, err := ParseInstruction("src.txt,dst.txt,hard=true", testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, instruction.Hard)
|
||||
})
|
||||
|
||||
t.Run("Instruction with delete flag", func(t *testing.T) {
|
||||
instruction, err := ParseInstruction("src.txt,dst.txt,delete=true", testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, instruction.Delete)
|
||||
assert.True(t, instruction.Force) // Delete implies Force
|
||||
})
|
||||
|
||||
t.Run("Legacy format", func(t *testing.T) {
|
||||
instruction, err := ParseInstruction("src.txt,dst.txt,true,false,true", testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, instruction.Force)
|
||||
assert.False(t, instruction.Hard)
|
||||
assert.True(t, instruction.Delete)
|
||||
})
|
||||
|
||||
t.Run("Comment line", func(t *testing.T) {
|
||||
_, err := ParseInstruction("# This is a comment", testDir)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "comment line")
|
||||
})
|
||||
|
||||
t.Run("Invalid format", func(t *testing.T) {
|
||||
_, err := ParseInstruction("src.txt", testDir)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "not enough parameters")
|
||||
})
|
||||
if tc.expectError {
|
||||
assert.Error(t, err)
|
||||
if tc.errorMsg != "" {
|
||||
assert.Contains(t, err.Error(), tc.errorMsg)
|
||||
}
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
if tc.assertions != nil {
|
||||
tc.assertions(t, instruction)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinkInstruction_RunAsync(t *testing.T) {
|
||||
@@ -1837,57 +1875,19 @@ func TestUtilEdgeCases(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// Test missing logger.go paths
|
||||
func TestLoggerFunctions(t *testing.T) {
|
||||
t.Run("LogInfo", func(t *testing.T) {
|
||||
// Test that LogInfo doesn't crash
|
||||
LogInfo("Test info message")
|
||||
})
|
||||
|
||||
t.Run("LogError", func(t *testing.T) {
|
||||
// Test that LogError doesn't crash
|
||||
LogError("Test error message")
|
||||
})
|
||||
|
||||
t.Run("LogSuccess", func(t *testing.T) {
|
||||
// Test that LogSuccess doesn't crash
|
||||
LogSuccess("Test success message")
|
||||
})
|
||||
|
||||
t.Run("LogTarget", func(t *testing.T) {
|
||||
// Test that LogTarget doesn't crash
|
||||
LogTarget("Test target message")
|
||||
})
|
||||
|
||||
t.Run("LogSource", func(t *testing.T) {
|
||||
// Test that LogSource doesn't crash
|
||||
LogSource("Test source message")
|
||||
})
|
||||
|
||||
t.Run("LogImportant", func(t *testing.T) {
|
||||
// Test that LogImportant doesn't crash
|
||||
LogImportant("Test important message")
|
||||
})
|
||||
|
||||
t.Run("LogPath", func(t *testing.T) {
|
||||
// Test that LogPath doesn't crash
|
||||
LogPath("Test path value")
|
||||
})
|
||||
|
||||
// Enhanced tests for path formatting functions
|
||||
func TestPathFormattingFunctions(t *testing.T) {
|
||||
t.Run("FormatSourcePath", func(t *testing.T) {
|
||||
// Test that FormatSourcePath doesn't crash
|
||||
result := FormatSourcePath("test/path")
|
||||
assert.Contains(t, result, "test/path")
|
||||
})
|
||||
|
||||
t.Run("FormatTargetPath", func(t *testing.T) {
|
||||
// Test that FormatTargetPath doesn't crash
|
||||
result := FormatTargetPath("test/path")
|
||||
assert.Contains(t, result, "test/path")
|
||||
})
|
||||
|
||||
t.Run("FormatPathValue", func(t *testing.T) {
|
||||
// Test that FormatPathValue doesn't crash
|
||||
result := FormatPathValue("test/path")
|
||||
assert.Contains(t, result, "test/path")
|
||||
})
|
||||
|
Reference in New Issue
Block a user