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
76
77
78
79
80
81
82
83
|
//go:build test
package runner
import (
"github.com/ewy1/pik/identity"
"github.com/ewy1/pik/model"
"github.com/stretchr/testify/assert"
"os/exec"
"testing"
)
func TTarget(name string, sub ...string) model.Target {
t := TestTarget{Id: identity.New(name), MyTags: model.TagsFromFilename(name), SubValue: sub}
return &t
}
func TSource(name string, targets ...string) *model.Source {
src := &model.Source{
Path: name,
Identity: identity.New(name),
}
for _, t := range targets {
src.Targets = append(src.Targets, TTarget(t))
}
return src
}
func TState(sources ...*model.Source) *model.State {
return &model.State{
Sources: sources,
}
}
type TestTarget struct {
Stub
Id identity.Identity
SubValue []string
MyTags model.Tags
}
func (t TestTarget) Invocation(src *model.Source) []string {
return []string{src.Identity.Reduced, t.Id.Reduced}
}
func (t TestTarget) Matches(input string) bool {
return t.Id.Is(input)
}
func (t TestTarget) Visible() bool {
return true
}
func (t TestTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) {
return HydratedStub{}, nil
}
func (t TestTarget) Sub() []string {
return t.SubValue
}
func (t TestTarget) Label() string {
return t.Id.Full
}
func (t TestTarget) Create(s *model.Source) *exec.Cmd {
panic("whadafak")
}
func AssertTargetIs(t *testing.T, input string, target model.Target) {
assert.Equal(t, input, target.Label())
}
func AssertTargetIsNot(t *testing.T, input string, target model.Target) {
assert.NotEqual(t, input, target.Label())
}
func AssertSourceIs(t *testing.T, input string, src *model.Source) {
assert.NotNil(t, src.Identity)
assert.Equal(t, input, src.Identity.Reduced)
}
func AssertSourceIsNot(t *testing.T, input string, src *model.Source) {
assert.NotNil(t, src.Identity)
assert.NotEqual(t, input, src.Identity.Reduced)
}
|