本文整理汇总了Golang中github.com/skriptble/nine/stream.Properties.Domain方法的典型用法代码示例。如果您正苦于以下问题:Golang Properties.Domain方法的具体用法?Golang Properties.Domain怎么用?Golang Properties.Domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skriptble/nine/stream.Properties
的用法示例。
在下文中一共展示了Properties.Domain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStartReceiving
func TestStartReceiving(t *testing.T) {
t.Parallel()
var want, got []byte
var props, gotProps stream.Properties
var err, wantErr error
pipe1, pipe2 := net.Pipe()
tcpTsp := NewTCP(pipe1, stream.Receiving, &tls.Config{}, true)
props.Header = stream.Header{}
// Should return Domain Not Set error if the domain isnot set on the
// stream properties.
_, err = tcpTsp.Start(props)
if err != stream.ErrDomainNotSet {
t.Error("Should return ErrDomainNotSet error if the domain is no set on the properties.")
t.Errorf("\nWant:%s\nGot :%s", stream.ErrDomainNotSet, err)
}
// Should return error from Next
props.Domain = "localhost"
err = pipe2.Close()
if err != nil {
t.Errorf("Unexpected error from pipe2.Close: %s", err)
}
_, err = tcpTsp.Start(props)
if err != io.EOF {
t.Error("Should return error from Next")
t.Errorf("\nWant:%s\nGot :%s", io.EOF, err)
}
// Should return error from NewHeader
pipe1, pipe2 = net.Pipe()
tcpTsp = NewTCP(pipe1, stream.Receiving, &tls.Config{}, true)
go func() {
_, err := pipe2.Write([]byte("<baz xmlns='foo:bar'/>"))
if err != nil {
t.Errorf("Unexpected error while writing to pipe2: %s", err)
}
}()
_, err = tcpTsp.Start(props)
wantErr = fmt.Errorf("Element is not <stream:stream> it is a <foo:bar:baz>")
if err.Error() != wantErr.Error() {
t.Error("Should return error from NewHeader")
t.Errorf("\nWant:%s\nGot :%s", wantErr, err)
}
// Should send HostUnknown if the to field of the header does not match the
// Domain field on properties
pipe1, pipe2 = net.Pipe()
tcpTsp = NewTCP(pipe1, stream.Receiving, &tls.Config{}, true)
go func() {
hdr := stream.Header{To: "not-localhost", From: "[email protected]"}
_, err := pipe2.Write(hdr.WriteBytes())
if err != nil {
t.Errorf("Unexpected error while writing to pipe2: %s", err)
}
hdr.To, hdr.From = hdr.From, "localhost"
want = hdr.WriteBytes()
// We need to add an extra 36 bytes for the id length
hdrLen := len(want) + 36
want = append(want, element.StreamError.HostUnknown.WriteBytes()...)
// We need to add an extra 36 bytes for the id length
got = make([]byte, len(want)+36)
_, err = pipe2.Read(got)
if err != nil {
t.Errorf("Unexpected error while reading from pipe2: %s", err)
}
_, err = pipe2.Read(got[hdrLen:])
if err != nil {
t.Errorf("Unexpected error while reading from pipe2: %s", err)
}
}()
gotProps, err = tcpTsp.Start(props)
if err != nil {
t.Errorf("Unexpected error from Start: %s", err)
}
if gotProps.Status != stream.Closed {
t.Error("Expected stream to be marked as closed after host unknown error")
}
// Need to remove stream ID before comparing
idx := bytes.Index(got, []byte("id='"))
if idx == -1 {
t.Error("Received stream is missing id attribute")
}
// We slice the id out of the received stream header.
got = append(got[:idx+4], got[idx+40:]...)
if !bytes.Equal(want, got) {
t.Error("Should send HostUnknown if the to field of the header does not match the domain field on properties.")
t.Errorf("\nWant:%s\nGot :%s", want, got)
}
// Should return error from writing header to the underlying connection
pipe1, pipe2 = net.Pipe()
tcpTsp = NewTCP(pipe1, stream.Receiving, &tls.Config{}, true)
go func() {
hdr := stream.Header{To: "localhost", From: "[email protected]"}
_, err := pipe2.Write(hdr.WriteBytes())
if err != nil {
t.Errorf("Unexpected error while writing to pipe2: %s", err)
//.........这里部分代码省略.........