From 907162be44661aa64f1b74212d853695b5a1dd20 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Tue, 16 Jun 2020 18:44:47 -0700 Subject: [PATCH] Add test for DefaultTemplates. --- templates/values_test.go | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 templates/values_test.go diff --git a/templates/values_test.go b/templates/values_test.go new file mode 100644 index 00000000..4bbaa8d3 --- /dev/null +++ b/templates/values_test.go @@ -0,0 +1,52 @@ +package templates + +import ( + "reflect" + "testing" +) + +func TestDefaultTemplates(t *testing.T) { + sshTemplates := DefaultSSHTemplates + sshTemplatesData := DefaultSSHTemplateData + t.Cleanup(func() { + DefaultSSHTemplates = sshTemplates + DefaultSSHTemplateData = sshTemplatesData + }) + + DefaultSSHTemplates = SSHTemplates{ + User: []Template{ + {Name: "foo.tpl", Type: Snippet, TemplatePath: "templates/ssh/foo.tpl", Path: "/tmp/foo", Comment: "#"}, + }, + Host: []Template{ + {Name: "bar.tpl", Type: Snippet, TemplatePath: "templates/ssh/bar.tpl", Path: "/tmp/bar", Comment: "#"}, + }, + } + DefaultSSHTemplateData = map[string]string{ + "foo.tpl": "foo", + "bar.tpl": "bar", + } + + tests := []struct { + name string + want *Templates + }{ + {"ok", &Templates{ + SSH: &SSHTemplates{ + User: []Template{ + {Name: "foo.tpl", Type: Snippet, Content: []byte("foo"), Path: "/tmp/foo", Comment: "#"}, + }, + Host: []Template{ + {Name: "bar.tpl", Type: Snippet, Content: []byte("bar"), Path: "/tmp/bar", Comment: "#"}, + }, + }, + Data: map[string]interface{}{}, + }}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := DefaultTemplates(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("DefaultTemplates() = %v, want %v", got, tt.want) + } + }) + } +}