summaryrefslogtreecommitdiff
path: root/runner
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-29 22:34:47 +0200
committerewy <ewy0@protonmail.com>2026-04-29 22:34:47 +0200
commit42fb6efd01e3640ea9d15dc1e0a072c1ea8295b1 (patch)
treeebf351b66f0288c8e9f879c529a962b025bebf15 /runner
parent03a31799a872385d821130f46942fc13dae76774 (diff)
fix very embarrassing bug where -a didnt actually work
Diffstat (limited to 'runner')
-rw-r--r--runner/create.go83
-rw-r--r--runner/create_test.go34
-rw-r--r--runner/stub.go7
3 files changed, 123 insertions, 1 deletions
diff --git a/runner/create.go b/runner/create.go
new file mode 100644
index 0000000..4e9035b
--- /dev/null
+++ b/runner/create.go
@@ -0,0 +1,83 @@
+//go:build test
+
+package runner
+
+import (
+ "github.com/stretchr/testify/assert"
+ "os/exec"
+ "pik/identity"
+ "pik/model"
+ "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)
+}
diff --git a/runner/create_test.go b/runner/create_test.go
new file mode 100644
index 0000000..fc9e535
--- /dev/null
+++ b/runner/create_test.go
@@ -0,0 +1,34 @@
+//go:build test
+
+package runner
+
+import (
+ "github.com/stretchr/testify/assert"
+ "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)
+}
+
+func TestTTargetIdentity(t *testing.T) {
+ ta := TTarget("asdf.hidden.sh")
+ assert.True(t, ta.Matches("asdf"))
+ assert.False(t, ta.Matches("hidden"))
+}
diff --git a/runner/stub.go b/runner/stub.go
index 3282fe8..9899b0d 100644
--- a/runner/stub.go
+++ b/runner/stub.go
@@ -11,6 +11,11 @@ import (
type Stub struct {
}
+func (s Stub) File(src *model.Source) string {
+ //TODO implement me
+ panic("implement me")
+}
+
func (s Stub) Matches(input string) bool {
//TODO implement me
panic("implement me")
@@ -108,7 +113,7 @@ func (h HydratedStub) Icon() string {
panic("implement me")
}
-func (h HydratedStub) Description() string {
+func (h HydratedStub) Description(src *model.HydratedSource) string {
//TODO implement me
panic("implement me")
}