forked from ns1/waitron
/
machine_test.go
46 lines (39 loc) · 1.14 KB
/
machine_test.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"strings"
"testing"
)
func TestmachineDefinition(t *testing.T) {
m, err := machineDefinition("my-service.example.com", "machines")
if err != nil {
t.Errorf("Unable to load test machine definition")
}
if m.Hostname != "my-service.example.com" {
t.Errorf("expected hostname: my-service.example.com")
}
if m.ShortName != "my-service" {
t.Errorf("invalid shortname")
}
}
func TestRenderTemplate(t *testing.T) {
config, _ := loadConfig("config.yaml")
m, _ := machineDefinition("my-service.example.com", "machines")
template, err := m.renderTemplate("finish.j2", config)
if err != nil {
t.Errorf("failed to render template")
}
expected := "example.com"
if !strings.Contains(template, expected) {
t.Errorf(fmt.Sprintf("Template does not contain '%s'", expected))
}
}
func TestRenderTemplateNotFound(t *testing.T) {
config, _ := loadConfig("config.yaml")
m, _ := machineDefinition("my-service.example.com", "machines")
_, err := m.renderTemplate("invalid.j2", config)
expected := "Template does not exist"
if err.Error() != expected {
t.Errorf(fmt.Sprintf("Expected: %s, got: %s", expected, err.Error()))
}
}