File tree Expand file tree Collapse file tree 2 files changed +50
-12
lines changed Expand file tree Collapse file tree 2 files changed +50
-12
lines changed Original file line number Diff line number Diff line change 1
1
package nuga
2
2
3
3
import (
4
- "github.com/mishamyrt/nuga-lib/device "
4
+ "github.com/mishamyrt/nuga-lib/dump "
5
5
"github.com/mishamyrt/nuga-lib/features"
6
6
)
7
7
8
8
const fakePath = "/simulated/device/path"
9
9
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
-
17
10
// FromTemplate creates simulated keyboard
18
- func FromTemplate (t * SimulationTemplate ) (* Device , error ) {
11
+ func FromTemplate (t * dump. State ) (* Device , error ) {
19
12
return & Device {
20
- Name : t .Name ,
13
+ Name : t .Model ,
21
14
Path : fakePath ,
22
15
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 ),
25
18
}, nil
26
19
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments