@@ -2,12 +2,14 @@ package nuga_test
2
2
3
3
import (
4
4
"encoding/json"
5
+ "errors"
5
6
"fmt"
6
7
"os"
7
8
"testing"
8
9
9
10
"github.com/mishamyrt/nuga-lib"
10
11
"github.com/mishamyrt/nuga-lib/dump"
12
+ "github.com/mishamyrt/nuga-lib/features/keys"
11
13
)
12
14
13
15
func readTemplate (model string ) (* dump.State , error ) {
@@ -25,21 +27,37 @@ func readTemplate(model string) (*dump.State, error) {
25
27
}
26
28
27
29
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
30
+ tests := []struct {
31
+ model string
32
+ expectKeysError bool
33
+ }{
34
+ {"Halo75" , false },
35
+ {"Halo65" , false },
36
+ {"Halo96" , true },
41
37
}
42
- if string (device .Name ) != model {
43
- t .Errorf ("Unexpected device name '%v'. Expected '%v'" , device .Name , model )
38
+ for _ , tt := range tests {
39
+ t .Run (tt .model , func (t * testing.T ) {
40
+ template , err := readTemplate (tt .model )
41
+ if err != nil {
42
+ t .Errorf ("Error while reading template: %v" , err )
43
+ }
44
+ device , err := nuga .FromTemplate (template )
45
+ if err != nil {
46
+ passError := tt .expectKeysError
47
+ if ! passError {
48
+ passError = passError && errors .Is (err , keys .ErrNoTemplate )
49
+ }
50
+ if ! passError {
51
+ t .Errorf ("Unexpected error on opening simulation: %v" , err )
52
+ }
53
+ }
54
+ if device == nil {
55
+ t .Error ("Expected non-nil device, got nil" )
56
+ return
57
+ }
58
+ if string (device .Name ) != tt .model {
59
+ t .Errorf ("Unexpected device name '%v'. Expected '%v'" , device .Name , tt .model )
60
+ }
61
+ })
44
62
}
45
63
}
0 commit comments