MCPcopy Create free account
hub / github.com/apache/thrift / TestWriteJSONProtocolString

Function TestWriteJSONProtocolString

lib/go/thrift/json_protocol_test.go:354–376  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

352}
353
354func TestWriteJSONProtocolString(t *testing.T) {
355 thetype := "string"
356 trans := NewTMemoryBuffer()
357 p := NewTJSONProtocol(trans)
358 for _, value := range STRING_VALUES {
359 if e := p.WriteString(context.Background(), value); e != nil {
360 t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
361 }
362 if e := p.Flush(context.Background()); e != nil {
363 t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
364 }
365 s := trans.String()
366 if s[0] != '"' || s[len(s)-1] != '"' {
367 t.Fatalf("Bad value for %s '%v', wrote '%v', expected: %v", thetype, value, s, fmt.Sprint("\"", value, "\""))
368 }
369 v := new(string)
370 if err := json.Unmarshal([]byte(s), v); err != nil || *v != value {
371 t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v)
372 }
373 trans.Reset()
374 }
375 trans.Close()
376}
377
378func TestReadJSONProtocolString(t *testing.T) {
379 thetype := "string"

Callers

nothing calls this directly

Calls 8

WriteStringMethod · 0.95
FlushMethod · 0.95
CloseMethod · 0.95
NewTMemoryBufferFunction · 0.85
NewTJSONProtocolFunction · 0.85
StringMethod · 0.65
ResetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected