Fix retarded tests

This commit is contained in:
2025-10-16 14:35:29 +02:00
parent 89e29eacee
commit a7d5317114

View File

@@ -344,11 +344,10 @@ func TestParseYAMLFile(t *testing.T) {
assert.NoError(t, err)
t.Run("YAML with glob pattern", func(t *testing.T) {
yamlContent := `links:
- source: src/*.txt
target: dst
force: true
hard: false`
yamlContent := `- source: src/*.txt
target: dst
force: true
hard: false`
yamlFile := filepath.Join(testDir, "sync.yaml")
err := os.WriteFile(yamlFile, []byte(yamlContent), 0644)
@@ -392,10 +391,9 @@ func TestParseYAMLFile(t *testing.T) {
})
t.Run("YAML with single file", func(t *testing.T) {
yamlContent := `links:
- source: src/file1.txt
target: dst/single.txt
force: true`
yamlContent := `- source: src/file1.txt
target: dst/single.txt
force: true`
yamlFile := filepath.Join(testDir, "sync2.yaml")
err := os.WriteFile(yamlFile, []byte(yamlContent), 0644)
@@ -525,11 +523,11 @@ func TestGetSyncFilesRecursively(t *testing.T) {
sync2 := filepath.Join(subdir1, "sync.yml")
sync3 := filepath.Join(subdir2, "sync.yaml")
err = os.WriteFile(sync1, []byte("links: []"), 0644)
err = os.WriteFile(sync1, []byte("[]"), 0644)
assert.NoError(t, err)
err = os.WriteFile(sync2, []byte("links: []"), 0644)
err = os.WriteFile(sync2, []byte("[]"), 0644)
assert.NoError(t, err)
err = os.WriteFile(sync3, []byte("links: []"), 0644)
err = os.WriteFile(sync3, []byte("[]"), 0644)
assert.NoError(t, err)
t.Run("Find sync files recursively", func(t *testing.T) {
@@ -615,10 +613,9 @@ func TestReadFromFile(t *testing.T) {
})
t.Run("YAML format", func(t *testing.T) {
yamlContent := `links:
- source: src.txt
target: dst.yaml
force: true`
yamlContent := `- source: src.txt
target: dst.yaml
force: true`
yamlFile := filepath.Join(testDir, "test.yaml")
err := os.WriteFile(yamlFile, []byte(yamlContent), 0644)
@@ -1600,7 +1597,7 @@ func TestErrorPaths(t *testing.T) {
// Create sync.yaml file
syncFile := filepath.Join(testDir, "sync.yaml")
err := os.WriteFile(syncFile, []byte("links: []"), 0644)
err := os.WriteFile(syncFile, []byte("[]"), 0644)
assert.NoError(t, err)
// Change to test directory to find the sync file
@@ -1623,7 +1620,7 @@ func TestErrorPaths(t *testing.T) {
// Create sync.yml file
syncFile := filepath.Join(testDir, "sync.yml")
err := os.WriteFile(syncFile, []byte("links: []"), 0644)
err := os.WriteFile(syncFile, []byte("[]"), 0644)
assert.NoError(t, err)
// Change to test directory to find the sync file
@@ -1654,7 +1651,6 @@ func TestErrorPaths(t *testing.T) {
// FormatErrorMessage just formats the message, no "ERROR" prefix
})
t.Run("RunAsync_error_handling", func(t *testing.T) {
// Test RunAsync error handling with invalid source
instruction := &LinkInstruction{
@@ -1851,7 +1847,7 @@ func TestMainFunctionsCoverage(t *testing.T) {
// Create sync.yaml file (but NOT sync or sync.yml)
syncFile := filepath.Join(testDir, "sync.yaml")
err := os.WriteFile(syncFile, []byte("links: []"), 0644)
err := os.WriteFile(syncFile, []byte("[]"), 0644)
assert.NoError(t, err)
instructions := make(chan *LinkInstruction, 10)
@@ -1872,7 +1868,7 @@ func TestMainFunctionsCoverage(t *testing.T) {
// Create sync.yml file (but NOT sync or sync.yaml)
syncFile := filepath.Join(testDir, "sync.yml")
err := os.WriteFile(syncFile, []byte("links: []"), 0644)
err := os.WriteFile(syncFile, []byte("[]"), 0644)
assert.NoError(t, err)
instructions := make(chan *LinkInstruction, 10)
@@ -2078,21 +2074,18 @@ func TestYAMLConfigFrom(t *testing.T) {
t.Run("ParseYAMLFileRecursive_simple_from", func(t *testing.T) {
// Create a referenced config file
referencedConfig := filepath.Join(testDir, "referenced.yaml")
referencedYAML := `links:
- source: src2.txt
target: dst2.txt
- source: src3.txt
target: dst3.txt`
referencedYAML := `- source: src2.txt
target: dst2.txt
- source: src3.txt
target: dst3.txt`
err := os.WriteFile(referencedConfig, []byte(referencedYAML), 0644)
assert.NoError(t, err)
// Create main config file that references the other
mainConfig := filepath.Join(testDir, "main.yaml")
mainYAML := `links:
- source: src1.txt
target: dst1.txt
from:
- referenced.yaml`
mainYAML := `- source: src1.txt
target: dst1.txt
- source: referenced.yaml`
err = os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)
@@ -2120,27 +2113,23 @@ from:
t.Run("ParseYAMLFileRecursive_multiple_from", func(t *testing.T) {
// Create multiple referenced config files
config1 := filepath.Join(testDir, "config1.yaml")
config1YAML := `links:
- source: src1.txt
target: dst1.txt`
config1YAML := `- source: src1.txt
target: dst1.txt`
err := os.WriteFile(config1, []byte(config1YAML), 0644)
assert.NoError(t, err)
config2 := filepath.Join(testDir, "config2.yaml")
config2YAML := `links:
- source: src2.txt
target: dst2.txt`
config2YAML := `- source: src2.txt
target: dst2.txt`
err = os.WriteFile(config2, []byte(config2YAML), 0644)
assert.NoError(t, err)
// Create main config that references both
mainConfig := filepath.Join(testDir, "main2.yaml")
mainYAML := `links:
- source: src3.txt
target: dst3.txt
from:
- config1.yaml
- config2.yaml`
mainYAML := `- source: src3.txt
target: dst3.txt
- source: config1.yaml
- source: config2.yaml`
err = os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)
@@ -2172,29 +2161,24 @@ from:
// Create a config file in the nested directory with relative paths
nestedConfig := filepath.Join(nestedDir, "nested.yaml")
nestedYAML := `links:
- source: nested_src.txt
target: nested_dst.txt`
nestedYAML := `- source: nested_src.txt
target: nested_dst.txt`
err = os.WriteFile(nestedConfig, []byte(nestedYAML), 0644)
assert.NoError(t, err)
// Create a config that references the nested one
intermediateConfig := filepath.Join(testDir, "intermediate.yaml")
intermediateYAML := `links:
- source: src2.txt
target: dst2.txt
from:
- nested/nested.yaml`
intermediateYAML := `- source: src2.txt
target: dst2.txt
- source: nested/nested.yaml`
err = os.WriteFile(intermediateConfig, []byte(intermediateYAML), 0644)
assert.NoError(t, err)
// Create main config that references the intermediate one
mainConfig := filepath.Join(testDir, "main3.yaml")
mainYAML := `links:
- source: src3.txt
target: dst3.txt
from:
- intermediate.yaml`
mainYAML := `- source: src3.txt
target: dst3.txt
- source: intermediate.yaml`
err = os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)
@@ -2216,19 +2200,16 @@ from:
t.Run("ParseYAMLFileRecursive_absolute_paths", func(t *testing.T) {
// Create a config file with absolute path reference
absoluteConfig := filepath.Join(testDir, "absolute.yaml")
absoluteYAML := `links:
- source: src1.txt
target: dst1.txt`
absoluteYAML := `- source: src1.txt
target: dst1.txt`
err := os.WriteFile(absoluteConfig, []byte(absoluteYAML), 0644)
assert.NoError(t, err)
// Create main config with absolute path reference
mainConfig := filepath.Join(testDir, "main4.yaml")
mainYAML := fmt.Sprintf(`links:
- source: src2.txt
target: dst2.txt
from:
- %s`, absoluteConfig)
mainYAML := fmt.Sprintf(`- source: src2.txt
target: dst2.txt
- source: %s`, absoluteConfig)
err = os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)
@@ -2249,20 +2230,16 @@ from:
t.Run("ParseYAMLFileRecursive_circular_reference", func(t *testing.T) {
// Create config files that reference each other (circular)
config1 := filepath.Join(testDir, "circular1.yaml")
config1YAML := `links:
- source: src1.txt
target: dst1.txt
from:
- circular2.yaml`
config1YAML := `- source: src1.txt
target: dst1.txt
- source: circular2.yaml`
err := os.WriteFile(config1, []byte(config1YAML), 0644)
assert.NoError(t, err)
config2 := filepath.Join(testDir, "circular2.yaml")
config2YAML := `links:
- source: src2.txt
target: dst2.txt
from:
- circular1.yaml`
config2YAML := `- source: src2.txt
target: dst2.txt
- source: circular1.yaml`
err = os.WriteFile(config2, []byte(config2YAML), 0644)
assert.NoError(t, err)
@@ -2275,11 +2252,9 @@ from:
t.Run("ParseYAMLFileRecursive_nonexistent_file", func(t *testing.T) {
// Create config that references a non-existent file
mainConfig := filepath.Join(testDir, "main5.yaml")
mainYAML := `links:
- source: src1.txt
target: dst1.txt
from:
- nonexistent.yaml`
mainYAML := `- source: src1.txt
target: dst1.txt
- source: nonexistent.yaml`
err := os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)
@@ -2292,9 +2267,8 @@ from:
t.Run("ParseYAMLFileRecursive_no_from", func(t *testing.T) {
// Create config without "from" field (should work like regular ParseYAMLFile)
mainConfig := filepath.Join(testDir, "main6.yaml")
mainYAML := `links:
- source: src1.txt
target: dst1.txt`
mainYAML := `- source: src1.txt
target: dst1.txt`
err := os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)
@@ -2309,10 +2283,8 @@ from:
t.Run("ParseYAMLFileRecursive_empty_from", func(t *testing.T) {
// Create config with empty "from" field
mainConfig := filepath.Join(testDir, "main7.yaml")
mainYAML := `links:
- source: src1.txt
target: dst1.txt
from: []`
mainYAML := `- source: src1.txt
target: dst1.txt`
err := os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)
@@ -2327,11 +2299,9 @@ from: []`
t.Run("ParseYAMLFileRecursive_self_reference", func(t *testing.T) {
// Create config that references itself
mainConfig := filepath.Join(testDir, "main8.yaml")
mainYAML := `links:
- source: src1.txt
target: dst1.txt
from:
- main8.yaml`
mainYAML := `- source: src1.txt
target: dst1.txt
- source: main8.yaml`
err := os.WriteFile(mainConfig, []byte(mainYAML), 0644)
assert.NoError(t, err)