From ac27c1f553e87e8433f99bad056b378b8ebf9085 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Fri, 6 May 2022 15:04:12 -0500 Subject: [PATCH] :white_check_mark: Add some tests --- cmd/version_test.go | 25 +++++++++++++++++++ internal/template/funcs_test.go | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 cmd/version_test.go create mode 100644 internal/template/funcs_test.go 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) + } + }) + } +}