-
Notifications
You must be signed in to change notification settings - Fork 1
/
model_test.go
33 lines (28 loc) · 900 Bytes
/
model_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
package main
import (
"io/ioutil"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExpectationsFromString(t *testing.T) {
str := "[{\"key\": \"k1\"},{\"key\": \"k2\"}]"
exps := ExpectationsFromString(str)
assert.Equal(t, 2, len(exps))
assert.Equal(t, "k1", exps[0].Key)
assert.Equal(t, "k2", exps[1].Key)
}
func TestExpectationsDefaultValues(t *testing.T) {
str := "[{\"key\": \"k1\", \"forward\":{\"host\":\"localhost\"}}]"
exps := ExpectationsFromString(str)
assert.Equal(t, 1, len(exps))
assert.Equal(t, "k1", exps[0].Key)
assert.NotNil(t, exps[0].Forward)
assert.Equal(t, "localhost", exps[0].Forward.Host)
assert.Equal(t, "http", exps[0].Forward.Scheme)
}
func TestConvertationExpectationFromReadCloser(t *testing.T) {
str := "{\"key\": \"k\"}"
exp := ExpectationFromReadCloser(ioutil.NopCloser(strings.NewReader(str)))
assert.Equal(t, "k", exp.Key)
}