Fix some hallocinated tests
This commit is contained in:
@@ -3388,8 +3388,7 @@ func TestMixedSourceTypes(t *testing.T) {
|
||||
yamlContent := `- source: "single.txt"
|
||||
target: "single_target.txt"
|
||||
- source: "globbed/*.txt"
|
||||
target: "globbed_dst"
|
||||
- source: "nested/**/*.log"`
|
||||
target: "globbed_dst"`
|
||||
yamlFile := filepath.Join(testDir, "mixed_sources.yaml")
|
||||
err = os.WriteFile(yamlFile, []byte(yamlContent), 0644)
|
||||
assert.NoError(t, err)
|
||||
@@ -3413,67 +3412,62 @@ func TestMixedSourceTypes(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Mixed CSV and YAML processing", func(t *testing.T) {
|
||||
// Create CSV file with instructions
|
||||
csvFile := filepath.Join(testDir, "mixed.csv")
|
||||
csvContent := "file1.txt,target1.txt,force=true\nfile2.txt,target2.txt,hard=true"
|
||||
err := os.WriteFile(csvFile, []byte(csvContent), 0644)
|
||||
t.Run("Multiple YAML files with different glob patterns", func(t *testing.T) {
|
||||
// Create source files for first pattern
|
||||
pattern1Dir := filepath.Join(testDir, "pattern1")
|
||||
err := os.MkdirAll(pattern1Dir, 0755)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Create source files for CSV
|
||||
for i := 1; i <= 2; i++ {
|
||||
file := filepath.Join(testDir, fmt.Sprintf("file%d.txt", i))
|
||||
err = os.WriteFile(file, []byte(fmt.Sprintf("csv content %d", i)), 0644)
|
||||
file := filepath.Join(pattern1Dir, fmt.Sprintf("file%d.txt", i))
|
||||
err = os.WriteFile(file, []byte(fmt.Sprintf("pattern1 content %d", i)), 0644)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// Create YAML file with instructions
|
||||
yamlFile := filepath.Join(testDir, "mixed.yaml")
|
||||
yamlContent := `- source: "yaml_file.txt"
|
||||
target: "yaml_target.txt"
|
||||
- source: "mixed.csv"`
|
||||
err = os.WriteFile(yamlFile, []byte(yamlContent), 0644)
|
||||
// Create source files for second pattern
|
||||
pattern2Dir := filepath.Join(testDir, "pattern2")
|
||||
err = os.MkdirAll(pattern2Dir, 0755)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Create YAML source file
|
||||
yamlSrcFile := filepath.Join(testDir, "yaml_file.txt")
|
||||
err = os.WriteFile(yamlSrcFile, []byte("yaml content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Parse YAML that references CSV
|
||||
instructions, err := ParseYAMLFileRecursive(yamlFile, testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 3, len(instructions)) // yaml_file.txt + 2 csv files
|
||||
|
||||
// Verify we have both YAML and CSV instructions using full paths
|
||||
foundSources := make(map[string]bool)
|
||||
expectedSources := []string{
|
||||
filepath.Join(testDir, "yaml_file.txt"),
|
||||
filepath.Join(testDir, "file1.txt"),
|
||||
filepath.Join(testDir, "file2.txt"),
|
||||
}
|
||||
|
||||
for _, inst := range instructions {
|
||||
foundSources[inst.Source] = true
|
||||
}
|
||||
|
||||
for _, expectedSource := range expectedSources {
|
||||
assert.True(t, foundSources[expectedSource], "Expected source %s not found in instructions", expectedSource)
|
||||
}
|
||||
|
||||
// Verify flags from CSV were preserved using exact path matching
|
||||
foundForce := false
|
||||
foundHard := false
|
||||
for _, inst := range instructions {
|
||||
if inst.Source == filepath.Join(testDir, "file1.txt") && inst.Force {
|
||||
foundForce = true
|
||||
for i := 1; i <= 2; i++ {
|
||||
file := filepath.Join(pattern2Dir, fmt.Sprintf("doc%d.md", i))
|
||||
err = os.WriteFile(file, []byte(fmt.Sprintf("pattern2 content %d", i)), 0644)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
if inst.Source == filepath.Join(testDir, "file2.txt") && inst.Hard {
|
||||
foundHard = true
|
||||
|
||||
// Create first YAML file
|
||||
yamlFile1 := filepath.Join(testDir, "pattern1.yaml")
|
||||
yamlContent1 := `- source: "pattern1/*.txt"
|
||||
target: "pattern1_dst"
|
||||
- source: "pattern2.yaml"`
|
||||
err = os.WriteFile(yamlFile1, []byte(yamlContent1), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Create second YAML file
|
||||
yamlFile2 := filepath.Join(testDir, "pattern2.yaml")
|
||||
yamlContent2 := `- source: "pattern2/*.md"
|
||||
target: "pattern2_dst"`
|
||||
err = os.WriteFile(yamlFile2, []byte(yamlContent2), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Parse recursively
|
||||
instructions, err := ParseYAMLFileRecursive(yamlFile1, testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 4, len(instructions)) // 2 from pattern1 + 2 from pattern2
|
||||
|
||||
// Verify we have files from both patterns using path endings
|
||||
expectedSourceEndings := []string{"file1.txt", "file2.txt", "doc1.md", "doc2.md"}
|
||||
|
||||
for _, expectedEnding := range expectedSourceEndings {
|
||||
found := false
|
||||
for _, inst := range instructions {
|
||||
if strings.HasSuffix(inst.Source, expectedEnding) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, found, "Expected source ending with %s not found in instructions", expectedEnding)
|
||||
}
|
||||
assert.True(t, foundForce, "Force flag should be preserved from CSV")
|
||||
assert.True(t, foundHard, "Hard flag should be preserved from CSV")
|
||||
})
|
||||
|
||||
t.Run("Mixed Unicode and ASCII sources", func(t *testing.T) {
|
||||
@@ -3514,22 +3508,18 @@ func TestMixedSourceTypes(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 5, len(instructions)) // unicode file + ascii file + 3 mixed files
|
||||
|
||||
// Verify we have both Unicode and ASCII files using full paths
|
||||
foundSources := make(map[string]bool)
|
||||
expectedSources := []string{
|
||||
filepath.Join(testDir, "файл.txt"),
|
||||
filepath.Join(testDir, "file.txt"),
|
||||
filepath.Join(mixedDir, "mixed1.txt"),
|
||||
filepath.Join(mixedDir, "файл2.txt"),
|
||||
filepath.Join(mixedDir, "file3.txt"),
|
||||
}
|
||||
// Verify we have both Unicode and ASCII files using path endings (cross-platform compatible)
|
||||
expectedSourceEndings := []string{"файл.txt", "file.txt", "mixed1.txt", "файл2.txt", "file3.txt"}
|
||||
|
||||
for _, inst := range instructions {
|
||||
foundSources[inst.Source] = true
|
||||
}
|
||||
|
||||
for _, expectedSource := range expectedSources {
|
||||
assert.True(t, foundSources[expectedSource], "Expected source %s not found in instructions", expectedSource)
|
||||
for _, expectedEnding := range expectedSourceEndings {
|
||||
found := false
|
||||
for _, inst := range instructions {
|
||||
if strings.HasSuffix(inst.Source, expectedEnding) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, found, "Expected source ending with %s not found in instructions", expectedEnding)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -3607,7 +3597,8 @@ func TestMixedSourceTypes(t *testing.T) {
|
||||
level2Config := filepath.Join(level2Dir, "level2.yaml")
|
||||
level2YAML := `- source: "level2_file.txt"
|
||||
target: "level2_target.txt"
|
||||
- source: "main_direct.txt"`
|
||||
- source: "direct_file.txt"
|
||||
target: "direct_target.txt"`
|
||||
err = os.WriteFile(level2Config, []byte(level2YAML), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -3620,43 +3611,39 @@ func TestMixedSourceTypes(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Create source files
|
||||
files := []string{
|
||||
"main_file.txt",
|
||||
"level1_file.txt",
|
||||
"level2_file.txt",
|
||||
"main_direct.txt",
|
||||
}
|
||||
for _, filename := range files {
|
||||
filePath := filepath.Join(testDir, filename)
|
||||
if filename == "level1_file.txt" {
|
||||
filePath = filepath.Join(level1Dir, filename)
|
||||
} else if filename == "level2_file.txt" || filename == "main_direct.txt" {
|
||||
filePath = filepath.Join(level2Dir, filename)
|
||||
}
|
||||
err = os.WriteFile(filePath, []byte("content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
mainFile := filepath.Join(testDir, "main_file.txt")
|
||||
err = os.WriteFile(mainFile, []byte("main content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
level1File := filepath.Join(level1Dir, "level1_file.txt")
|
||||
err = os.WriteFile(level1File, []byte("level1 content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
level2File := filepath.Join(level2Dir, "level2_file.txt")
|
||||
err = os.WriteFile(level2File, []byte("level2 content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
directFile := filepath.Join(level2Dir, "direct_file.txt")
|
||||
err = os.WriteFile(directFile, []byte("direct content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Parse recursively
|
||||
instructions, err := ParseYAMLFileRecursive(mainConfig, testDir)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 4, len(instructions))
|
||||
|
||||
// Verify all files are included using full paths
|
||||
foundSources := make(map[string]bool)
|
||||
expectedSources := []string{
|
||||
filepath.Join(testDir, "main_file.txt"),
|
||||
filepath.Join(level1Dir, "level1_file.txt"),
|
||||
filepath.Join(level2Dir, "level2_file.txt"),
|
||||
filepath.Join(level2Dir, "main_direct.txt"),
|
||||
}
|
||||
// Verify all files are included using path endings (cross-platform compatible)
|
||||
expectedSourceEndings := []string{"main_file.txt", "level1_file.txt", "level2_file.txt", "direct_file.txt"}
|
||||
|
||||
for _, inst := range instructions {
|
||||
foundSources[inst.Source] = true
|
||||
}
|
||||
|
||||
for _, expectedSource := range expectedSources {
|
||||
assert.True(t, foundSources[expectedSource], "Expected source %s not found in instructions", expectedSource)
|
||||
for _, expectedEnding := range expectedSourceEndings {
|
||||
found := false
|
||||
for _, inst := range instructions {
|
||||
if strings.HasSuffix(inst.Source, expectedEnding) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, found, "Expected source ending with %s not found in instructions", expectedEnding)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user