config_test.go 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package control
  2. import (
  3. "bytes"
  4. "os"
  5. "strings"
  6. "testing"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestGenTpl(t *testing.T) {
  10. assert := require.New(t)
  11. tpl := `
  12. services:
  13. {{if eq "amd64" .ARCH -}}
  14. acpid:
  15. image: rancher/os-acpid:0.x.x
  16. labels:
  17. io.rancher.os.scope: system
  18. net: host
  19. uts: host
  20. privileged: true
  21. volumes_from:
  22. - command-volumes
  23. - system-volumes
  24. {{end -}}
  25. all-volumes:`
  26. for _, tc := range []struct {
  27. arch string
  28. expected string
  29. }{
  30. {"amd64", `
  31. services:
  32. acpid:
  33. image: rancher/os-acpid:0.x.x
  34. labels:
  35. io.rancher.os.scope: system
  36. net: host
  37. uts: host
  38. privileged: true
  39. volumes_from:
  40. - command-volumes
  41. - system-volumes
  42. all-volumes:`},
  43. {"arm", `
  44. services:
  45. all-volumes:`},
  46. } {
  47. out := &bytes.Buffer{}
  48. os.Setenv("ARCH", tc.arch)
  49. genTpl(strings.NewReader(tpl), out)
  50. assert.Equal(tc.expected, out.String(), tc.arch)
  51. }
  52. }