-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathexecutor_test.go
75 lines (59 loc) · 1.55 KB
/
executor_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package borges
import (
"context"
"io/ioutil"
"strings"
"testing"
"github.com/src-d/borges/storage"
"github.com/stretchr/testify/suite"
"gopkg.in/src-d/core-retrieval.v0/test"
"gopkg.in/src-d/go-kallax.v1"
"gopkg.in/src-d/go-log.v1"
"gopkg.in/src-d/go-queue.v1/memory"
)
type ExecutorSuite struct {
test.Suite
store RepositoryStore
}
func (s *ExecutorSuite) SetupTest() {
s.Setup()
s.store = storage.Local()
}
func (s *ExecutorSuite) TearDownTest() {
s.TearDown()
}
func (s *ExecutorSuite) TestExecute() {
jobs, err := s.runExecutor(
"git://foo.bar/baz",
"https://foo.bar",
)
require := s.Require()
require.NoError(err)
require.Len(jobs, 2)
s.assertRepo("git://foo.bar/baz", jobs[0])
s.assertRepo("https://foo.bar", jobs[1])
}
func (s *ExecutorSuite) assertRepo(endpoint string, job *Job) {
require := s.Require()
repos, err := s.store.GetByEndpoints(endpoint)
require.NoError(err)
require.Len(repos, 1)
require.Equal(kallax.ULID(job.RepositoryID), repos[0].ID)
}
func (s *ExecutorSuite) runExecutor(repos ...string) ([]*Job, error) {
require := s.Require()
q, err := memory.NewFinite(true).Queue(kallax.NewULID().String())
require.NoError(err)
r := ioutil.NopCloser(strings.NewReader(strings.Join(repos, "\n")))
var jobs []*Job
wp := NewWorkerPool(func(ctx context.Context, logger log.Logger, j *Job) error {
jobs = append(jobs, j)
return nil
})
wp.SetWorkerCount(1)
e := NewExecutor(q, wp, s.store, NewLineJobIter(r, s.store))
return jobs, e.Execute()
}
func TestExecutor(t *testing.T) {
suite.Run(t, new(ExecutorSuite))
}