Skip to content

Commit 730a790

Browse files
committed
feat: update simulation
1 parent 22cd62b commit 730a790

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

simulation.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
package nuga
22

33
import (
4-
"github.com/mishamyrt/nuga-lib/device"
4+
"github.com/mishamyrt/nuga-lib/dump"
55
"github.com/mishamyrt/nuga-lib/features"
66
)
77

88
const fakePath = "/simulated/device/path"
99

10-
// SimulationTemplate represents template for simulated keyboard
11-
type SimulationTemplate struct {
12-
Name device.Model `json:"name"`
13-
Firmware string `json:"firmware"`
14-
Data *features.StateData `json:"data"`
15-
}
16-
1710
// FromTemplate creates simulated keyboard
18-
func FromTemplate(t *SimulationTemplate) (*Device, error) {
11+
func FromTemplate(t *dump.State) (*Device, error) {
1912
return &Device{
20-
Name: t.Name,
13+
Name: t.Model,
2114
Path: fakePath,
2215
Firmware: t.Firmware,
23-
Features: features.NewSimulation(t.Data, t.Name),
24-
Capabilities: GetCapabilities(t.Name),
16+
Features: features.NewSimulation(&t.Data, t.Model),
17+
Capabilities: GetCapabilities(t.Model),
2518
}, nil
2619
}

simulation_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package nuga_test
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
"testing"
8+
9+
"github.com/mishamyrt/nuga-lib"
10+
"github.com/mishamyrt/nuga-lib/dump"
11+
)
12+
13+
func readTemplate(model string) (*dump.State, error) {
14+
path := fmt.Sprintf("dump/defaults/%v.nugafile", model)
15+
content, err := os.ReadFile(path)
16+
if err != nil {
17+
return nil, err
18+
}
19+
var template dump.State
20+
err = json.Unmarshal(content, &template)
21+
if err != nil {
22+
return nil, err
23+
}
24+
return &template, nil
25+
}
26+
27+
func TestOpenSimulation(t *testing.T) {
28+
t.Parallel()
29+
model := "Halo75"
30+
template, err := readTemplate(model)
31+
if err != nil {
32+
t.Errorf("Error while reading template: %v", err)
33+
}
34+
device, err := nuga.FromTemplate(template)
35+
if err != nil {
36+
t.Errorf("Expected error on opening simulation: %v", err)
37+
}
38+
if device == nil {
39+
t.Error("Expected non-nil device, got nil")
40+
return
41+
}
42+
if string(device.Name) != model {
43+
t.Errorf("Unexpected device name '%v'. Expected '%v'", device.Name, model)
44+
}
45+
}

0 commit comments

Comments
 (0)