forked from pufferpanel/pufferpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_test.go
More file actions
71 lines (67 loc) · 1.89 KB
/
server_test.go
File metadata and controls
71 lines (67 loc) · 1.89 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
64
65
66
67
68
69
70
71
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
expectedValue interface{}
}{
{
name: "DefaultString",
args: []byte(`{ "type": "", "value": "0.0.0.0", "display": "IP", "desc": "What IP to bind the server to", "required": true }`),
expectedType: "string",
expectedValue: "0.0.0.0",
},
{
name: "TypeInt",
args: []byte(`{ "type": "integer", "value": 12345, "display": "Port", "desc": "Port", "required": true }`),
expectedType: "integer",
expectedValue: 12345,
},
{
name: "TypeNoValue",
args: []byte(`{ "type": "string", "display": "Port", "desc": "Port", "required": true }`),
expectedType: "string",
expectedValue: "",
},
{
name: "TypeNoValueInt",
args: []byte(`{ "type": "integer", "display": "Port", "desc": "Port", "required": true }`),
expectedType: "integer",
expectedValue: 0,
},
}
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)
assert.Equal(t, tt.expectedValue, v.Value)
})
}
}