Skip to content

Commit

Permalink
chore(testing): make SkipTags public accessable
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Aug 3, 2023
1 parent 2402576 commit a84809b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions testing/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/foomo/go/testing/tag"
)

const envTestTags = "GO_TEST_TAGS"
const EnvTestTags = "GO_TEST_TAGS"

// Tags defines the tags that the test should run under.
//
Expand Down Expand Up @@ -39,18 +39,19 @@ func Tags(t *testing.T, tags ...tag.Tag) {
return
}

if skipTags(tags) {
if SkipTags(tags...) {
t.Skipf("skipping test with tag: %s", tags)
}
}

func skipTags(tags []tag.Tag) bool {
// SkipTags returns true if the tag rules apply
func SkipTags(tags ...tag.Tag) bool {
// always skip if no tags are provided so it can be used as block tests
if len(tags) == 0 {
return true
}

envTags := osx.GetenvStringSlice(envTestTags, nil)
envTags := osx.GetenvStringSlice(EnvTestTags, nil)
// always return false if there are non tags defined
if envTags == nil {
return false
Expand Down
11 changes: 6 additions & 5 deletions testing/tag_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package testing //nolint:testpackage
package testing_test

import (
"os"
"testing"

testingx "github.com/foomo/go/testing"
"github.com/foomo/go/testing/tag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_skipTags(t *testing.T) {
func TestSkipTags(t *testing.T) {
tests := []struct {
name string
env string
Expand Down Expand Up @@ -93,11 +94,11 @@ func Test_skipTags(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.env == "" {
require.NoError(t, os.Unsetenv(envTestTags))
require.NoError(t, os.Unsetenv(testingx.EnvTestTags))
} else {
require.NoError(t, os.Setenv(envTestTags, tt.env))
require.NoError(t, os.Setenv(testingx.EnvTestTags, tt.env))
}
assert.Equalf(t, tt.want, skipTags(tt.tags), "skipTags(%v)", tt.tags)
assert.Equalf(t, tt.want, testingx.SkipTags(tt.tags...), "skipTags(%v)", tt.tags)
})
}
}

0 comments on commit a84809b

Please sign in to comment.