aboutsummaryrefslogtreecommitdiff
path: root/internal/behavior/yml_test.go
blob: 9452e9e9df8a86d5c37da653d4c99f6859143d4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package behavior

import (
	"os"
	"path/filepath"
	"testing"
)

// Regression: WalkYAMLDir only matched .yaml, so a .yml trigger file loaded
// and fired at runtime while every validation pass ignored it.
func TestWalkYAMLDirIncludesYml(t *testing.T) {
	dir := t.TempDir()
	if err := os.WriteFile(filepath.Join(dir, "a.yaml"), []byte("x: 1"), 0644); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(filepath.Join(dir, "b.yml"), []byte("x: 2"), 0644); err != nil {
		t.Fatal(err)
	}
	ids := map[string]bool{}
	if err := WalkYAMLDir(dir, func(path, id string, data []byte) error {
		ids[id] = true
		return nil
	}); err != nil {
		t.Fatal(err)
	}
	if !ids["a"] || !ids["b"] {
		t.Fatalf("WalkYAMLDir ids = %v, want both a and b", ids)
	}
}