-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulation_test.go
More file actions
63 lines (59 loc) · 1.37 KB
/
Copy pathsimulation_test.go
File metadata and controls
63 lines (59 loc) · 1.37 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
package nuga_test
import (
"encoding/json"
"errors"
"fmt"
"os"
"testing"
"github.com/mishamyrt/nuga-lib"
"github.com/mishamyrt/nuga-lib/device"
"github.com/mishamyrt/nuga-lib/features/keys"
)
func readTemplate(model string) (*device.State, error) {
path := fmt.Sprintf("device/defaults/%v.nugafile", model)
content, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var template device.State
err = json.Unmarshal(content, &template)
if err != nil {
return nil, err
}
return &template, nil
}
func TestOpenSimulation(t *testing.T) {
tests := []struct {
model string
expectKeysError bool
}{
{"Halo75", false},
{"Halo65", false},
{"Halo96", true},
}
for _, tt := range tests {
t.Run(tt.model, func(t *testing.T) {
template, err := readTemplate(tt.model)
if err != nil {
t.Errorf("Error while reading template: %v", err)
}
device, err := nuga.FromTemplate(template)
if err != nil {
passError := tt.expectKeysError
if !passError {
passError = passError && errors.Is(err, keys.ErrNoTemplate)
}
if !passError {
t.Errorf("Unexpected error on opening simulation: %v", err)
}
}
if device == nil {
t.Error("Expected non-nil device, got nil")
return
}
if string(device.Name) != tt.model {
t.Errorf("Unexpected device name '%v'. Expected '%v'", device.Name, tt.model)
}
})
}
}