-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_test.go
More file actions
197 lines (165 loc) · 5.96 KB
/
command_test.go
File metadata and controls
197 lines (165 loc) · 5.96 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package play
import (
"testing"
"dappco.re/go/core"
)
func TestCommand_Commands_Good(testingT *testing.T) {
testingT.Parallel()
commands := Commands()
if len(commands) != 6 {
testingT.Fatalf("unexpected command count: %d", len(commands))
}
if commands[0] != CommandPlay {
testingT.Fatalf("unexpected first command: %q", commands[0])
}
}
func TestCommand_Commands_Bad(testingT *testing.T) {
testingT.Parallel()
commands := Commands()
for _, command := range commands {
if command == "" {
testingT.Fatal("Commands returned an empty command name")
}
}
}
func TestCommand_Commands_Ugly(testingT *testing.T) {
testingT.Parallel()
first := Commands()
second := Commands()
first[0] = "changed"
if second[0] != CommandPlay {
testingT.Fatal("Commands should return an isolated slice on each call")
}
}
func TestCommand_Register_Good(testingT *testing.T) {
testingT.Parallel()
c := core.New()
Register(c)
commands := c.Commands()
if len(commands) != 6 {
testingT.Fatalf("unexpected registered command count: %d", len(commands))
}
if commands[0] != CommandPlay {
testingT.Fatalf("unexpected first registered command: %q", commands[0])
}
}
func TestCommand_Register_Bad(testingT *testing.T) {
testingT.Parallel()
Register(nil)
}
func TestCommand_Register_Ugly(testingT *testing.T) {
testingT.Parallel()
c := core.New()
Register(c)
Register(c)
if len(c.Commands()) != 6 {
testingT.Fatalf("duplicate Register changed command count: %d", len(c.Commands()))
}
}
func TestCommand_PlayRequest_Good(testingT *testing.T) {
testingT.Parallel()
result := cmdPlay(core.NewOptions(core.Option{Key: "name", Value: "mega-lo-mania"}))
request := result.Value.(PlayRequest)
if request.BundlePath != "mega-lo-mania" {
testingT.Fatalf("unexpected play bundle path: %q", request.BundlePath)
}
}
func TestCommand_ListRequest_Good(testingT *testing.T) {
testingT.Parallel()
result := cmdPlayList(core.NewOptions(
core.Option{Key: "root", Value: "games"},
core.Option{Key: "json", Value: true},
))
request := result.Value.(ListRequest)
if request.Root != "games" {
testingT.Fatalf("unexpected list root: %q", request.Root)
}
if !request.JSON {
testingT.Fatal("expected list JSON option to be preserved")
}
}
func TestCommand_VerifyRequest_Good(testingT *testing.T) {
testingT.Parallel()
result := cmdPlayVerify(core.NewOptions(core.Option{Key: "bundle", Value: "mega-lo-mania"}))
request := result.Value.(VerifyRequest)
if request.BundlePath != "mega-lo-mania" {
testingT.Fatalf("unexpected verify bundle path: %q", request.BundlePath)
}
}
func TestCommand_BundleRequest_Good(testingT *testing.T) {
testingT.Parallel()
artefactData := []byte("rom")
engineData := []byte("engine")
result := cmdPlayBundle(core.NewOptions(
core.Option{Key: "name", Value: "mega-lo-mania"},
core.Option{Key: "title", Value: "Mega lo Mania"},
core.Option{Key: "author", Value: "Sensible Software"},
core.Option{Key: "year", Value: 1991},
core.Option{Key: "platform", Value: "sega-genesis"},
core.Option{Key: "genre", Value: "strategy"},
core.Option{Key: "licence", Value: "freeware"},
core.Option{Key: "engine", Value: "retroarch"},
core.Option{Key: "profile", Value: "genesis"},
core.Option{Key: "acceleration", Value: "auto"},
core.Option{Key: "filter", Value: "nearest"},
core.Option{Key: "rom", Value: "rom/MegaLoMania.zip"},
core.Option{Key: "artefact_data", Value: artefactData},
core.Option{Key: "artefact_sha256", Value: hashHex(artefactData)},
core.Option{Key: "artefact_size", Value: int64(len(artefactData))},
core.Option{Key: "media_type", Value: "application/zip"},
core.Option{Key: "source", Value: "rights-cleared"},
core.Option{Key: "engine_binary", Value: "engine/retroarch"},
core.Option{Key: "engine_binary_data", Value: engineData},
core.Option{Key: "engine_binary_sha256", Value: hashHex(engineData)},
core.Option{Key: "cpu_percent", Value: 75},
core.Option{Key: "memory_bytes", Value: int64(268435456)},
core.Option{Key: "distribution_mode", Value: "catalogue"},
core.Option{Key: "byorom", Value: true},
core.Option{Key: "entrypoint", Value: "rom/MegaLoMania.zip"},
core.Option{Key: "config", Value: "emulator.yaml"},
core.Option{Key: "chain", Value: "checksums.sha256"},
core.Option{Key: "sbom", Value: "sbom.json"},
core.Option{Key: "save_path", Value: "saves/"},
core.Option{Key: "screenshot_path", Value: "screenshots/"},
))
request := result.Value.(BundleRequest)
if request.Year != 1991 {
testingT.Fatalf("unexpected bundle year: %d", request.Year)
}
if request.ArtefactPath != "rom/MegaLoMania.zip" {
testingT.Fatalf("unexpected artefact path: %q", request.ArtefactPath)
}
if request.ResourceLimits.CPUPercent != 75 {
testingT.Fatalf("unexpected CPU limit: %d", request.ResourceLimits.CPUPercent)
}
if request.ResourceLimits.MemoryBytes != 268435456 {
testingT.Fatalf("unexpected memory limit: %d", request.ResourceLimits.MemoryBytes)
}
if !request.BYOROM {
testingT.Fatal("expected BYOROM option to be preserved")
}
if string(request.ArtefactData) != "rom" {
testingT.Fatalf("unexpected artefact data: %q", string(request.ArtefactData))
}
if string(request.EngineBinaryData) != "engine" {
testingT.Fatalf("unexpected engine data: %q", string(request.EngineBinaryData))
}
}
func TestCommand_BundleRequest_Ugly(testingT *testing.T) {
testingT.Parallel()
result := cmdPlayBundle(core.NewOptions(
core.Option{Key: "artefact", Value: "rom/fallback.zip"},
core.Option{Key: "cpu-percent", Value: 55},
core.Option{Key: "memory-bytes", Value: int64(1024)},
))
request := result.Value.(BundleRequest)
if request.ArtefactPath != "rom/fallback.zip" {
testingT.Fatalf("unexpected fallback artefact path: %q", request.ArtefactPath)
}
if request.ResourceLimits.CPUPercent != 55 {
testingT.Fatalf("unexpected fallback CPU limit: %d", request.ResourceLimits.CPUPercent)
}
if request.ResourceLimits.MemoryBytes != 1024 {
testingT.Fatalf("unexpected fallback memory limit: %d", request.ResourceLimits.MemoryBytes)
}
}