summaryrefslogtreecommitdiff
path: root/testx/create.go
blob: 306e50aa332146d71df094d1ef8560d29bc0a887 (plain)
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
//go:build test

package testx

import (
	"github.com/stretchr/testify/assert"
	"os/exec"
	"pik/identity"
	"pik/model"
	"pik/runner"
	"testing"
)

func TTarget(name string) model.Target {
	return TestTarget{Identifier: name}
}

func TSource(name string, targets ...string) *model.Source {
	src := &model.Source{
		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 {
	runner.BaseTarget
	Identifier string
	SubValue   []string
	Tags       model.Tags
}

func (t TestTarget) Visible() bool {
	return true
}

func (t TestTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) {
	//TODO implement me
	panic("implement me")
}

func (t TestTarget) Sub() []string {
	return t.SubValue
}

func (t TestTarget) Label() string {
	return t.Identifier
}

func (t TestTarget) Matches(input string) bool {
	return input == t.Identifier
}

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.Equal(t, input, src.Identity.Reduced)
}
func AssertSourceIsNot(t *testing.T, input string, src *model.Source) {
	assert.NotEqual(t, input, src.Identity.Reduced)
}