embed_test.go 920 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package data
  2. import (
  3. "path/filepath"
  4. "strings"
  5. "testing"
  6. )
  7. // TestBotPoliciesEmbed ensures all YAML files in the directory tree
  8. // are accessible in the embedded BotPolicies filesystem.
  9. func TestBotPoliciesEmbed(t *testing.T) {
  10. yamlFiles, err := filepath.Glob("./**/*.yaml")
  11. if err != nil {
  12. t.Fatalf("Failed to glob YAML files: %v", err)
  13. }
  14. if len(yamlFiles) == 0 {
  15. t.Fatal("No YAML files found in directory tree")
  16. }
  17. t.Logf("Found %d YAML files to verify", len(yamlFiles))
  18. for _, filePath := range yamlFiles {
  19. embeddedPath := strings.TrimPrefix(filePath, "./")
  20. t.Run(embeddedPath, func(t *testing.T) {
  21. content, err := BotPolicies.ReadFile(embeddedPath)
  22. if err != nil {
  23. t.Errorf("Failed to read %s from embedded filesystem: %v", embeddedPath, err)
  24. return
  25. }
  26. if len(content) == 0 {
  27. t.Errorf("File %s exists in embedded filesystem but is empty", embeddedPath)
  28. }
  29. })
  30. }
  31. }