forked from mszostok/codeowners-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_test.go
43 lines (35 loc) · 1001 Bytes
/
package_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package check_test
import (
"context"
"errors"
"testing"
"github.com/mszostok/codeowners-validator/internal/check"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRespectingCanceledContext(t *testing.T) {
must := func(checker check.Checker, err error) check.Checker {
require.NoError(t, err)
return checker
}
checkers := []check.Checker{
check.NewDuplicatedPattern(),
check.NewFileExist(),
check.NewValidSyntax(),
check.NewNotOwnedFile(check.NotOwnedFileConfig{}),
must(check.NewValidOwner(check.ValidOwnerConfig{Repository: "org/repo"}, nil)),
}
for _, checker := range checkers {
sut := checker
t.Run(checker.Name(), func(t *testing.T) {
// given: canceled context
ctx, cancel := context.WithCancel(context.Background())
cancel()
// when
out, err := sut.Check(ctx, check.LoadInput(check.FixtureValidCODEOWNERS))
// then
assert.True(t, errors.Is(err, context.Canceled))
assert.Empty(t, out)
})
}
}