-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_test.go
More file actions
130 lines (109 loc) · 3.11 KB
/
app_test.go
File metadata and controls
130 lines (109 loc) · 3.11 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package core_test
import (
. "dappco.re/go"
)
// --- App.New ---
func TestApp_New_Good(t *T) {
app := App{}.New(NewOptions(
Option{Key: "name", Value: "myapp"},
Option{Key: "version", Value: "1.0.0"},
Option{Key: "description", Value: "test app"},
))
AssertEqual(t, "myapp", app.Name)
AssertEqual(t, "1.0.0", app.Version)
AssertEqual(t, "test app", app.Description)
}
func TestApp_New_Empty_Good(t *T) {
app := App{}.New(NewOptions())
AssertEqual(t, "", app.Name)
AssertEqual(t, "", app.Version)
}
func TestApp_New_Partial_Good(t *T) {
app := App{}.New(NewOptions(
Option{Key: "name", Value: "myapp"},
))
AssertEqual(t, "myapp", app.Name)
AssertEqual(t, "", app.Version)
}
// --- App via Core ---
func TestApp_Core_Good(t *T) {
c := New(WithOption("name", "myapp"))
AssertEqual(t, "myapp", c.App().Name)
}
func TestApp_Core_Empty_Good(t *T) {
c := New()
AssertNotNil(t, c.App())
AssertEqual(t, "", c.App().Name)
}
func TestApp_Runtime_Good(t *T) {
c := New()
c.App().Runtime = &struct{ Name string }{Name: "wails"}
AssertNotNil(t, c.App().Runtime)
}
// --- App.Find ---
func TestApp_Find_Good(t *T) {
r := App{}.Find("go", "go")
AssertTrue(t, r.OK)
app := r.Value.(*App)
AssertNotEmpty(t, app.Path)
}
func TestApp_Find_Bad(t *T) {
r := App{}.Find("nonexistent-binary-xyz", "test")
AssertFalse(t, r.OK)
}
// --- AX-7 canonical triplets ---
func TestApp_App_New_Good(t *T) {
app := App{}.New(NewOptions(
Option{Key: "name", Value: "Lethean Agent"},
Option{Key: "version", Value: "0.9.0"},
Option{Key: "description", Value: "agent dispatch runtime"},
Option{Key: "filename", Value: "lethean-agent"},
))
AssertEqual(t, "Lethean Agent", app.Name)
AssertEqual(t, "0.9.0", app.Version)
AssertEqual(t, "agent dispatch runtime", app.Description)
AssertEqual(t, "lethean-agent", app.Filename)
}
func TestApp_App_New_Bad(t *T) {
app := App{}.New(NewOptions())
AssertEqual(t, "", app.Name)
AssertEqual(t, "", app.Version)
AssertEqual(t, "", app.Description)
}
func TestApp_App_New_Ugly(t *T) {
base := App{Name: "Existing", Version: "0.8.0", Description: "old", Filename: "old-agent"}
app := base.New(NewOptions(Option{Key: "name", Value: "Updated"}))
AssertEqual(t, "Updated", app.Name)
AssertEqual(t, "0.8.0", app.Version)
AssertEqual(t, "old", app.Description)
AssertEqual(t, "old-agent", app.Filename)
}
func TestApp_App_Find_Good(t *T) {
dir := t.TempDir()
bin := Path(dir, "agent-dispatch")
AssertTrue(t, WriteFile(bin, []byte("#!/bin/sh\n"), 0755).OK)
r := App{}.Find(bin, "Agent Dispatch")
AssertTrue(t, r.OK)
app := r.Value.(*App)
AssertEqual(t, "Agent Dispatch", app.Name)
AssertEqual(t, bin, app.Filename)
AssertEqual(t, bin, app.Path)
}
func TestApp_App_Find_Bad(t *T) {
r := App{}.Find("definitely-missing-agent-binary", "Missing Agent")
AssertFalse(t, r.OK)
}
func TestApp_App_Find_Ugly(t *T) {
oldPath, hadPath := LookupEnv("PATH")
RequireTrue(t, Setenv("PATH", "").OK)
defer func() {
if hadPath {
Setenv("PATH", oldPath)
} else {
Unsetenv("PATH")
}
}()
r := App{}.Find("agent-dispatch", "Agent Dispatch")
AssertFalse(t, r.OK)
AssertContains(t, r.Error(), "PATH is empty")
}