func TestValueEqual(t *testing.T) { is := is.New(t) v := ParseValue([]byte("something")) is.True(v.Equal("something")) is.False(v.Equal("else")) is.Equal("string", v.Type()) v = ParseValue([]byte("123")) is.Equal("float64", v.Type()) v = ParseValue([]byte("/^2.{2}$/")) is.True(v.Equal(200)) is.True(v.Equal(201)) is.False(v.Equal(404)) is.Equal("regex", v.Type()) v = ParseValue([]byte("/application/json/")) is.True(v.Equal("application/json")) is.True(v.Equal("application/json; charset=utf-8")) is.True(v.Equal("text/xml; application/json; charset=utf-8")) is.False(v.Equal("text/xml; charset=utf-8")) is.Equal("regex", v.Type()) is.Equal(`/application/json/`, v.String()) v = ParseValue([]byte("/Silk/")) is.True(v.Equal("My name is Silk.")) is.True(v.Equal("Silk is my name.")) is.False(v.Equal("I don't contain that word!")) }
func TestValueEqual(t *testing.T) { is := is.New(t) v := ParseValue([]byte("something")) is.True(v.Equal("something")) is.False(v.Equal("else")) is.Equal("string", v.Type()) v = ParseValue([]byte("123")) is.Equal("float64", v.Type()) v = ParseValue([]byte("/^2.{2}$/")) is.True(v.Equal(200)) is.True(v.Equal(201)) is.False(v.Equal(404)) is.Equal("regex", v.Type()) v = ParseValue([]byte("/application/json/")) is.True(v.Equal("application/json")) is.True(v.Equal("application/json; charset=utf-8")) is.True(v.Equal("text/xml; application/json; charset=utf-8")) is.False(v.Equal("text/xml; charset=utf-8")) is.Equal("regex", v.Type()) }
func TestJvInvalid(t *testing.T) { is := is.New(t) jv := jq.JvInvalid() is.False(jv.IsValid()) _, ok := jv.Copy().GetInvalidMessageAsString() is.False(ok) // "Expected no Invalid message" jv = jv.GetInvalidMessage() is.Equal(jv.Kind(), jq.JV_KIND_NULL) }
func TestMatch(t *testing.T) { is := is.New(t) e1 := &testEncoder{} e2 := &testEncoder{} e3 := &testEncoder{} e := encoding.New() e.Default = respond.JSON e.Add("json", e1) e.Add("XML", e2) // Match json, ok := e.Match("application/JSON") is.True(ok) is.Equal(json, e1) json = e.EncoderFunc(nil, testRequestWithAccept("application/json")) is.Equal(json, e1) xml, ok := e.Match("text/xml") is.True(ok) is.Equal(xml, e2) xml = e.EncoderFunc(nil, testRequestWithAccept("text/xml")) is.True(ok) is.Equal(xml, e2) // no responder csv, ok := e.Match("text/csv") is.False(ok) is.Nil(csv) csv = e.EncoderFunc(nil, testRequestWithAccept("text/csv")) is.Nil(csv) is.Equal(e.Default, csv) // add e.Add("csv", e3) csv, ok = e.Match("text/xml") is.True(ok) is.Equal(csv, e3) // remove e.Del(e2) xml, ok = e.Match("text/xml") is.False(ok) is.Nil(xml) }
// https://github.com/matryer/silk/issues/31 func TestIssue31(t *testing.T) { is := is.New(t) subT := &testT{} s := httptest.NewServer(testutil.EchoHandler()) defer s.Close() r := runner.New(subT, s.URL) r.RunFile("../testfiles/success/issue-31.silk.md") is.False(subT.Failed()) }
func TestRunFileSuccessNoBody(t *testing.T) { is := is.New(t) subT := &testT{} s := httptest.NewServer(testutil.EchoHandler()) defer s.Close() r := runner.New(subT, s.URL) r.RunFile("../testfiles/success/echo.nobody.success.silk.md") is.False(subT.Failed()) }
func TestBodyField(t *testing.T) { is := is.New(t) subT := &testT{} s := httptest.NewServer(testutil.EchoDataHandler()) defer s.Close() r := runner.New(subT, s.URL) r.RunFile("../testfiles/success/body-as-field.silk.md") is.False(subT.Failed()) }
// https://github.com/matryer/silk/issues/37 func TestStandardSeparator(t *testing.T) { is := is.New(t) subT := &testT{} s := httptest.NewServer(testutil.EchoHandler()) defer s.Close() os.Setenv("$AppNameFromEnv", "Silk") r := runner.New(subT, s.URL) r.RunFile("../testfiles/success/issue-37.silk.md") is.False(subT.Failed()) }
// https://github.com/matryer/silk/issues/2 func TestCapturedVars(t *testing.T) { is := is.New(t) subT := &testT{} s := httptest.NewServer(testutil.EchoDataHandler()) defer s.Close() os.Setenv("$EnvStatus", "awesome") os.Setenv("$AppNameFromEnv", "Silk") r := runner.New(subT, s.URL) r.RunFile("../testfiles/success/captured-vars.silk.md") is.False(subT.Failed()) }
func TestRunJsonModesSuccess(t *testing.T) { is := is.New(t) subT := &testT{} s := httptest.NewServer(testutil.EchoRawHandler()) defer s.Close() r := runner.New(subT, s.URL) g, err := parse.ParseFile("../testfiles/success/echoraw.success.jsonmodes.silk.md") is.NoErr(err) r.RunGroup(g...) is.False(subT.Failed()) }
func TestJvInvalidWithMessage_string(t *testing.T) { is := is.New(t) jv := jq.JvInvalidWithMessage(jq.JvFromString("Error message 1")) is.False(jv.IsValid()) msg := jv.Copy().GetInvalidMessage() is.Equal(msg.Kind(), jq.JV_KIND_STRING) msg.Free() str, ok := jv.GetInvalidMessageAsString() is.True(ok) is.Equal("Error message 1", str) }
func TestJvInvalidWithMessage_object(t *testing.T) { is := is.New(t) jv := jq.JvInvalidWithMessage(jq.JvObject()) is.False(jv.IsValid()) msg := jv.Copy().GetInvalidMessage() is.Equal(msg.Kind(), jq.JV_KIND_OBJECT) msg.Free() str, ok := jv.GetInvalidMessageAsString() is.True(ok) is.Equal("{}", str) }