diff options
Diffstat (limited to 'testx')
| -rw-r--r-- | testx/create.go | 75 | ||||
| -rw-r--r-- | testx/create_test.go | 27 |
2 files changed, 102 insertions, 0 deletions
diff --git a/testx/create.go b/testx/create.go new file mode 100644 index 0000000..7153e54 --- /dev/null +++ b/testx/create.go @@ -0,0 +1,75 @@ +//go:build test + +package testx + +import ( + "github.com/stretchr/testify/assert" + "os/exec" + "pik/identity" + "pik/model" + "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 { + 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) +} diff --git a/testx/create_test.go b/testx/create_test.go new file mode 100644 index 0000000..c9f2925 --- /dev/null +++ b/testx/create_test.go @@ -0,0 +1,27 @@ +//go:build test + +package testx + +import ( + "testing" +) + +func TestAssertSourceIs_Correct(t *testing.T) { + src := TSource("abc", "def") + AssertSourceIs(t, "abc", src) +} + +func TestAssertSourceIs_Wrong(t *testing.T) { + src := TSource("abc", "def") + AssertSourceIsNot(t, ";lkjh", src) +} + +func TestAssertTargetIs_Correct(t *testing.T) { + ta := TTarget("aaaa") + AssertTargetIs(t, "aaaa", ta) +} + +func TestAssertTargetIs_Wrong(t *testing.T) { + ta := TTarget("aaaa") + AssertTargetIsNot(t, "bbbbbb", ta) +} |
