MCPcopy
hub / github.com/golang/protobuf / TestMarshalIllegalTime

Function TestMarshalIllegalTime

jsonpb/json_test.go:530–556  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

528}
529
530func TestMarshalIllegalTime(t *testing.T) {
531 tests := []struct {
532 pb proto.Message
533 fail bool
534 }{
535 {&durpb.Duration{Seconds: 1, Nanos: 0}, false},
536 {&durpb.Duration{Seconds: -1, Nanos: 0}, false},
537 {&durpb.Duration{Seconds: 1, Nanos: -1}, true},
538 {&durpb.Duration{Seconds: -1, Nanos: 1}, true},
539 {&durpb.Duration{Seconds: 315576000001}, true},
540 {&durpb.Duration{Seconds: -315576000001}, true},
541 {&durpb.Duration{Seconds: 1, Nanos: 1000000000}, true},
542 {&durpb.Duration{Seconds: -1, Nanos: -1000000000}, true},
543 {&tspb.Timestamp{Seconds: 1, Nanos: 1}, false},
544 {&tspb.Timestamp{Seconds: 1, Nanos: -1}, true},
545 {&tspb.Timestamp{Seconds: 1, Nanos: 1000000000}, true},
546 }
547 for _, tt := range tests {
548 _, err := marshaler.MarshalToString(tt.pb)
549 if err == nil && tt.fail {
550 t.Errorf("marshaler.MarshalToString(%v) = _, <nil>; want _, <non-nil>", tt.pb)
551 }
552 if err != nil && !tt.fail {
553 t.Errorf("marshaler.MarshalToString(%v) = _, %v; want _, <nil>", tt.pb, err)
554 }
555 }
556}
557
558func TestMarshalJSONPBMarshaler(t *testing.T) {
559 rawJson := `{ "foo": "bar", "baz": [0, 1, 2, 3] }`

Callers

nothing calls this directly

Calls 1

MarshalToStringMethod · 0.80

Tested by

no test coverage detected