/
server_test.go
55 lines (51 loc) · 1.37 KB
/
server_test.go
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
package pufferpanel
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestParseRequirementRow(t *testing.T) {
tests := []struct {
str string
want []string
}{
{str: "", want: []string{}},
{str: "linux", want: []string{"linux"}},
{str: " linux ", want: []string{"linux"}},
{str: "linux||windows", want: []string{"linux", "windows"}},
{str: " linux || windows ", want: []string{"linux", "windows"}},
}
for _, tt := range tests {
got := parseRequirementRow(tt.str)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseRequirementRow(%#v) = %v, want %v", tt.str, got, tt.want)
}
}
}
func TestVariable_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
args []byte
expectedType string
}{
{
name: "DefaultString",
args: []byte(`{ "type": "", "value": "0.0.0.0", "display": "IP", "desc": "What IP to bind the server to", "required": true }`),
expectedType: "string",
},
{
name: "TypeInt",
args: []byte(`{ "type": "integer", "value": 12345, "display": "Port", "desc": "Port", "required": true }`),
expectedType: "integer",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var v Variable
err := json.Unmarshal(tt.args, &v)
assert.NoError(t, err)
assert.Equal(t, tt.expectedType, v.Type.Type)
})
}
}