From 374ed5e1a4dc635c42e33e4133729d40cf3e0e35 Mon Sep 17 00:00:00 2001 From: ewy Date: Wed, 22 Apr 2026 18:29:37 +0200 Subject: work on tests also replace the annoying search return with a struct --- testx/create.go | 29 ++++++++++++++++++----------- testx/create_test.go | 7 +++++++ 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'testx') diff --git a/testx/create.go b/testx/create.go index 306e50a..62960fd 100644 --- a/testx/create.go +++ b/testx/create.go @@ -11,8 +11,9 @@ import ( "testing" ) -func TTarget(name string) model.Target { - return TestTarget{Identifier: name} +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 { @@ -32,10 +33,18 @@ func TState(sources ...*model.Source) *model.State { } type TestTarget struct { - runner.BaseTarget - Identifier string - SubValue []string - Tags model.Tags + runner.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 { @@ -52,11 +61,7 @@ func (t TestTarget) Sub() []string { } func (t TestTarget) Label() string { - return t.Identifier -} - -func (t TestTarget) Matches(input string) bool { - return input == t.Identifier + return t.Id.Full } func (t TestTarget) Create(s *model.Source) *exec.Cmd { @@ -70,8 +75,10 @@ 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) } diff --git a/testx/create_test.go b/testx/create_test.go index c9f2925..d0e3099 100644 --- a/testx/create_test.go +++ b/testx/create_test.go @@ -3,6 +3,7 @@ package testx import ( + "github.com/stretchr/testify/assert" "testing" ) @@ -25,3 +26,9 @@ func TestAssertTargetIs_Wrong(t *testing.T) { ta := TTarget("aaaa") AssertTargetIsNot(t, "bbbbbb", ta) } + +func TestTTargetIdentity(t *testing.T) { + ta := TTarget("asdf.hidden.sh") + assert.True(t, ta.Matches("asdf")) + assert.False(t, ta.Matches("hidden")) +} -- cgit v1.3.1