2018-09-12 19:18:01 +02:00
|
|
|
package pipe
|
2017-08-20 21:35:46 +02:00
|
|
|
|
|
|
|
import (
|
2017-09-12 05:22:02 +02:00
|
|
|
"errors"
|
2017-08-20 21:35:46 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-08-20 21:35:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSkipPipe(t *testing.T) {
|
2021-04-19 14:31:57 +02:00
|
|
|
reason := "this is a test"
|
|
|
|
err := Skip(reason)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Equal(t, reason, err.Error())
|
2017-08-20 21:35:46 +02:00
|
|
|
}
|
2017-09-12 05:22:02 +02:00
|
|
|
|
|
|
|
func TestIsSkip(t *testing.T) {
|
2020-10-06 14:48:04 +02:00
|
|
|
require.True(t, IsSkip(Skip("whatever")))
|
|
|
|
require.False(t, IsSkip(errors.New("nope")))
|
2017-09-12 05:22:02 +02:00
|
|
|
}
|
2020-08-16 16:29:56 +02:00
|
|
|
|
|
|
|
func TestSkipMemento(t *testing.T) {
|
2021-04-19 14:31:57 +02:00
|
|
|
m := SkipMemento{}
|
2020-08-16 16:29:56 +02:00
|
|
|
m.Remember(Skip("foo"))
|
|
|
|
m.Remember(Skip("bar"))
|
|
|
|
// test duplicated errors
|
|
|
|
m.Remember(Skip("dupe"))
|
|
|
|
m.Remember(Skip("dupe"))
|
2020-10-06 14:48:04 +02:00
|
|
|
require.EqualError(t, m.Evaluate(), `foo, bar, dupe`)
|
|
|
|
require.True(t, IsSkip(m.Evaluate()))
|
2020-08-16 16:29:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSkipMementoNoErrors(t *testing.T) {
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, (&SkipMemento{}).Evaluate())
|
2020-08-16 16:29:56 +02:00
|
|
|
}
|