2019-11-15 16:41:40 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTemplates(t *testing.T) {
|
|
|
|
name := "foo"
|
2019-11-21 20:31:13 +03:00
|
|
|
version := "123"
|
2019-11-29 14:35:00 +03:00
|
|
|
typ := "service"
|
2020-04-23 15:53:42 +03:00
|
|
|
namespace := "default"
|
2019-11-15 16:41:40 +03:00
|
|
|
|
|
|
|
// Render default service
|
2020-04-23 15:53:42 +03:00
|
|
|
s := NewService(name, version, typ, namespace)
|
2019-11-15 16:41:40 +03:00
|
|
|
bs := new(bytes.Buffer)
|
2019-11-21 20:31:13 +03:00
|
|
|
if err := renderTemplate(templates["service"], bs, s); err != nil {
|
2019-11-15 16:41:40 +03:00
|
|
|
t.Errorf("Failed to render kubernetes service: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render default deployment
|
2020-04-23 15:53:42 +03:00
|
|
|
d := NewDeployment(name, version, typ, namespace)
|
2019-11-15 16:41:40 +03:00
|
|
|
bd := new(bytes.Buffer)
|
2019-11-21 20:31:13 +03:00
|
|
|
if err := renderTemplate(templates["deployment"], bd, d); err != nil {
|
2019-11-15 16:41:40 +03:00
|
|
|
t.Errorf("Failed to render kubernetes deployment: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2019-11-25 19:31:14 +03:00
|
|
|
|
|
|
|
func TestFormatName(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
expect string
|
|
|
|
}{
|
|
|
|
{"foobar", "foobar"},
|
|
|
|
{"foo-bar", "foo-bar"},
|
|
|
|
{"foo.bar", "foo-bar"},
|
|
|
|
{"Foo.Bar", "foo-bar"},
|
|
|
|
{"go.micro.foo.bar", "go-micro-foo-bar"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
v := Format(test.name)
|
|
|
|
if v != test.expect {
|
|
|
|
t.Fatalf("Expected name %s for %s got: %s", test.expect, test.name, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|