24 lines
783 B
Go
24 lines
783 B
Go
package contracts
|
|
|
|
import "testing"
|
|
|
|
func TestValidateTranscriptEnvelope(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, input string
|
|
valid bool
|
|
}{
|
|
{"empty segments", `{"segments":[]}`, true},
|
|
{"other members", `{"extra":true,"segments":[null,{"anything":1}]}`, true},
|
|
{"malformed", `{`, false}, {"missing", `{}`, false}, {"null segments", `{"segments":null}`, false},
|
|
{"object segments", `{"segments":{}}`, false}, {"string segments", `{"segments":"x"}`, false},
|
|
{"null root", `null`, false}, {"array root", `[]`, false}, {"string root", `"text"`, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := ValidateTranscriptEnvelope([]byte(tc.input))
|
|
if (err == nil) != tc.valid {
|
|
t.Fatalf("error = %v, valid = %t", err, tc.valid)
|
|
}
|
|
})
|
|
}
|
|
}
|