-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22ed5aa
commit aa7f3b3
Showing
2 changed files
with
130 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package testing | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/foomo/go/testing/tag" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_skipTags(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
env string | ||
tags []tag.Tag | ||
want bool | ||
}{ | ||
{ | ||
name: "skip for nil", | ||
env: "", | ||
tags: nil, | ||
want: true, | ||
}, | ||
{ | ||
name: "skip for nil and short", | ||
env: "short", | ||
tags: nil, | ||
want: true, | ||
}, | ||
{ | ||
name: "skip for empty and short", | ||
env: "short", | ||
tags: []tag.Tag{}, | ||
want: true, | ||
}, | ||
{ | ||
name: "skip for empty and short", | ||
env: "short", | ||
tags: []tag.Tag{}, | ||
want: true, | ||
}, | ||
{ | ||
name: "skip for short and integration", | ||
env: "short", | ||
tags: []tag.Tag{tag.Integration, tag.Security}, | ||
want: true, | ||
}, | ||
{ | ||
name: "skip for short and integration,security", | ||
env: "short", | ||
tags: []tag.Tag{tag.Integration, tag.Security}, | ||
want: true, | ||
}, | ||
{ | ||
name: "don't skip for integration and integration", | ||
env: "integration", | ||
tags: []tag.Tag{tag.Integration}, | ||
want: false, | ||
}, | ||
{ | ||
name: "don't skip for integration and integration,security", | ||
env: "integration", | ||
tags: []tag.Tag{tag.Integration, tag.Security}, | ||
want: false, | ||
}, | ||
{ | ||
name: "don't skip for security and integration,security", | ||
env: "security", | ||
tags: []tag.Tag{tag.Integration, tag.Security}, | ||
want: false, | ||
}, | ||
{ | ||
name: "skip for security and -integration,security", | ||
env: "-integration,security", | ||
tags: []tag.Tag{tag.Integration, tag.Security}, | ||
want: true, | ||
}, | ||
{ | ||
name: "skip for security and integration,-security", | ||
env: "integration,-security", | ||
tags: []tag.Tag{tag.Integration, tag.Security}, | ||
want: true, | ||
}, | ||
} | ||
|
||
require.NoError(t, os.Setenv(envTestTags, "short,integration,security")) | ||
assert.False(t, skipTags([]tag.Tag{tag.Integration, tag.Security})) | ||
|
||
require.NoError(t, os.Setenv(envTestTags, "short,integration,-security")) | ||
assert.True(t, skipTags([]tag.Tag{tag.Integration, tag.Security})) | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if tt.env == "" { | ||
require.NoError(t, os.Unsetenv(envTestTags)) | ||
} else { | ||
require.NoError(t, os.Setenv(envTestTags, tt.env)) | ||
} | ||
assert.Equalf(t, tt.want, skipTags(tt.tags), "skipTags(%v)", tt.tags) | ||
}) | ||
} | ||
} |