values_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package templates
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestDefaultTemplates(t *testing.T) {
  7. sshTemplates := DefaultSSHTemplates
  8. sshTemplatesData := DefaultSSHTemplateData
  9. t.Cleanup(func() {
  10. DefaultSSHTemplates = sshTemplates
  11. DefaultSSHTemplateData = sshTemplatesData
  12. })
  13. DefaultSSHTemplates = SSHTemplates{
  14. User: []Template{
  15. {Name: "foo.tpl", Type: Snippet, TemplatePath: "templates/ssh/foo.tpl", Path: "/tmp/foo", Comment: "#"},
  16. },
  17. Host: []Template{
  18. {Name: "bar.tpl", Type: Snippet, TemplatePath: "templates/ssh/bar.tpl", Path: "/tmp/bar", Comment: "#"},
  19. },
  20. }
  21. DefaultSSHTemplateData = map[string]string{
  22. "foo.tpl": "foo",
  23. "bar.tpl": "bar",
  24. }
  25. tests := []struct {
  26. name string
  27. want *Templates
  28. }{
  29. {"ok", &Templates{
  30. SSH: &SSHTemplates{
  31. User: []Template{
  32. {Name: "foo.tpl", Type: Snippet, Content: []byte("foo"), Path: "/tmp/foo", Comment: "#"},
  33. },
  34. Host: []Template{
  35. {Name: "bar.tpl", Type: Snippet, Content: []byte("bar"), Path: "/tmp/bar", Comment: "#"},
  36. },
  37. },
  38. Data: map[string]interface{}{},
  39. }},
  40. }
  41. for _, tt := range tests {
  42. t.Run(tt.name, func(t *testing.T) {
  43. if got := DefaultTemplates(); !reflect.DeepEqual(got, tt.want) {
  44. t.Errorf("DefaultTemplates() = %v, want %v", got, tt.want)
  45. }
  46. })
  47. }
  48. }