diff --git a/cmd/version_test.go b/cmd/version_test.go new file mode 100644 index 0000000..c30b6dd --- /dev/null +++ b/cmd/version_test.go @@ -0,0 +1,25 @@ +package cmd + +import "testing" + +func Test_buildVersion(t *testing.T) { + t.Run("no commit", func(t *testing.T) { + Version = "0.0.0-next" + Commit = "" + v := buildVersion() + want := Version + if v != want { + t.Errorf("buildVersion() got = %v, want %v", v, want) + } + }) + + t.Run("commit", func(t *testing.T) { + Version = "0.0.0-next" + Commit = "123" + v := buildVersion() + want := Version + " (" + Commit + ")" + if v != want { + t.Errorf("buildVersion() got = %v, want %v", v, want) + } + }) +} diff --git a/internal/template/funcs_test.go b/internal/template/funcs_test.go new file mode 100644 index 0000000..d5469b2 --- /dev/null +++ b/internal/template/funcs_test.go @@ -0,0 +1,43 @@ +package template + +import "testing" + +func TestDockerRepo(t *testing.T) { + type args struct { + image string + } + tests := []struct { + name string + args args + want string + }{ + {"postgres:alpine", args{"postgres:alpine"}, "postgres"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := DockerRepo(tt.args.image); got != tt.want { + t.Errorf("DockerRepo() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDockerTag(t *testing.T) { + type args struct { + image string + } + tests := []struct { + name string + args args + want string + }{ + {"postgres:alpine", args{"postgres:alpine"}, "alpine"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := DockerTag(tt.args.image); got != tt.want { + t.Errorf("DockerTag() = %v, want %v", got, tt.want) + } + }) + } +}