From ce53e219897f9bc2efae7054645cc3c51ef0fa34 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 9 Nov 2017 13:30:33 +0800 Subject: [PATCH] add unit test. Signed-off-by: Bo-Yi Wu --- docker_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docker_test.go b/docker_test.go index ffd1cf2..7781593 100644 --- a/docker_test.go +++ b/docker_test.go @@ -23,3 +23,45 @@ func Test_stripHeadPrefix(t *testing.T) { } } } + +func TestUseDefaultTag(t *testing.T) { + type args struct { + ref string + defaultBranch string + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "latest tag for default branch", + args: args{ + ref: "refs/heads/master", + defaultBranch: "master", + }, + want: true, + }, + { + name: "build from tags", + args: args{ + ref: "refs/tags/v1.0.0", + defaultBranch: "master", + }, + want: true, + }, + { + name: "skip build for not default branch", + args: args{ + ref: "refs/heads/develop", + defaultBranch: "master", + }, + want: false, + }, + } + for _, tt := range tests { + if got := UseDefaultTag(tt.args.ref, tt.args.defaultBranch); got != tt.want { + t.Errorf("%q. UseDefaultTag() = %v, want %v", tt.name, got, tt.want) + } + } +}