Skip to content

Commit

Permalink
✅ Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed May 6, 2022
1 parent d992295 commit ac27c1f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
43 changes: 43 additions & 0 deletions internal/template/funcs_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}

0 comments on commit ac27c1f

Please sign in to comment.