Skip to content
Snippets Groups Projects
Commit fc554083 authored by Paul B's avatar Paul B
Browse files

test: add a test for new ShouldUpload function

parent 9eec92c8
Branches
Tags
No related merge requests found
package common package common
import ( import (
"errors"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
...@@ -38,3 +39,40 @@ func TestCacheCheckPolicy(t *testing.T) { ...@@ -38,3 +39,40 @@ func TestCacheCheckPolicy(t *testing.T) {
} }
} }
func doTestArtifactShouldUpload(t *testing.T, when ArtifactWhen, stateOK, expected bool) {
artifact := Artifact{When: when}
var state error
if !stateOK {
state = errors.New("Build error")
}
result := artifact.ShouldUpload(state)
if expected {
assert.True(t, result, "ShouldUpload should return true for when=%v and state=%v", when, state)
} else {
assert.False(t, result, "ShouldUpload should return false for when=%v and state=%v", when, state)
}
}
func TestArtifact_ShouldUpload(t *testing.T) {
examples := []struct {
when ArtifactWhen
stateOK bool
expected bool
}{
{when: "", stateOK: true, expected: true},
{when: ArtifactWhenOnSuccess, stateOK: true, expected: true},
{when: ArtifactWhenOnFailure, stateOK: true, expected: false},
{when: ArtifactWhenAlways, stateOK: true, expected: true},
{when: "", stateOK: false, expected: false},
{when: ArtifactWhenOnSuccess, stateOK: false, expected: false},
{when: ArtifactWhenOnFailure, stateOK: false, expected: true},
{when: ArtifactWhenAlways, stateOK: false, expected: true},
}
for _, example := range examples {
doTestArtifactShouldUpload(t, example.when, example.stateOK, example.expected)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment