From 11e803d6f0fb1c0cb095a79dc605c5b61fed0d4a Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 23 Oct 2019 09:38:22 +0200 Subject: [PATCH] when: fix typo in tag matching Add related tests --- services/types/when.go | 2 +- services/types/when_test.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/services/types/when.go b/services/types/when.go index 109c3cd..f43811c 100644 --- a/services/types/when.go +++ b/services/types/when.go @@ -58,7 +58,7 @@ func MatchWhen(when *When, refType itypes.RunRefType, branch, tag, ref string) b } } // test only if tag is not empty, if empty mean that we are not in a tag - if refType == itypes.RunRefTypeBranch && when.Tag != nil && tag != "" { + if refType == itypes.RunRefTypeTag && when.Tag != nil && tag != "" { // first check includes and override with excludes if matchCondition(when.Tag.Include, tag) { include = true diff --git a/services/types/when_test.go b/services/types/when_test.go index cb14fab..e119341 100644 --- a/services/types/when_test.go +++ b/services/types/when_test.go @@ -284,7 +284,7 @@ func TestMatchWhen(t *testing.T) { out: false, }, { - name: "test only matching reftype", + name: "test only matching branch reftype", when: &When{ Branch: &WhenConditions{ Include: []WhenCondition{ @@ -298,6 +298,21 @@ func TestMatchWhen(t *testing.T) { tag: "master", out: false, }, + { + name: "test only matching tag reftype", + when: &When{ + Tag: &WhenConditions{ + Include: []WhenCondition{ + {Type: WhenConditionTypeSimple, Match: "master"}, + }, + }, + }, + refType: itypes.RunRefTypeBranch, + branch: "master", + // we provide also a value to tag (should not be done) + tag: "master", + out: false, + }, } for _, tt := range tests {