xmpp/xmpp_test.go
changeset 147 d7679d991b17
parent 142 0ff033eed887
child 163 3f891f7fe817
equal deleted inserted replaced
146:aa9a0ae8f875 147:d7679d991b17
    11 
    11 
    12 func TestReadError(t *testing.T) {
    12 func TestReadError(t *testing.T) {
    13 	r := strings.NewReader(`<stream:error><bad-foo xmlns="blah"/>` +
    13 	r := strings.NewReader(`<stream:error><bad-foo xmlns="blah"/>` +
    14 		`</stream:error>`)
    14 		`</stream:error>`)
    15 	ch := make(chan interface{})
    15 	ch := make(chan interface{})
    16 	go readXml(r, ch, make(map[xml.Name]reflect.Type))
    16 	go recvXml(r, ch, make(map[xml.Name]reflect.Type))
    17 	x := <-ch
    17 	x := <-ch
    18 	se, ok := x.(*streamError)
    18 	se, ok := x.(*streamError)
    19 	if !ok {
    19 	if !ok {
    20 		t.Fatalf("not StreamError: %T", x)
    20 		t.Fatalf("not StreamError: %T", x)
    21 	}
    21 	}
    27 
    27 
    28 	r = strings.NewReader(`<stream:error><bad-foo xmlns="blah"/>` +
    28 	r = strings.NewReader(`<stream:error><bad-foo xmlns="blah"/>` +
    29 		`<text xml:lang="en" xmlns="` + NsStreams +
    29 		`<text xml:lang="en" xmlns="` + NsStreams +
    30 		`">Error text</text></stream:error>`)
    30 		`">Error text</text></stream:error>`)
    31 	ch = make(chan interface{})
    31 	ch = make(chan interface{})
    32 	go readXml(r, ch, make(map[xml.Name]reflect.Type))
    32 	go recvXml(r, ch, make(map[xml.Name]reflect.Type))
    33 	x = <-ch
    33 	x = <-ch
    34 	se, ok = x.(*streamError)
    34 	se, ok = x.(*streamError)
    35 	if !ok {
    35 	if !ok {
    36 		t.Fatalf("not StreamError: %v", reflect.TypeOf(x))
    36 		t.Fatalf("not StreamError: %v", reflect.TypeOf(x))
    37 	}
    37 	}
    45 	r := strings.NewReader(`<stream:stream to="foo.com" ` +
    45 	r := strings.NewReader(`<stream:stream to="foo.com" ` +
    46 		`from="bar.org" id="42"` +
    46 		`from="bar.org" id="42"` +
    47 		`xmlns="` + NsClient + `" xmlns:stream="` + NsStream +
    47 		`xmlns="` + NsClient + `" xmlns:stream="` + NsStream +
    48 		`" version="1.0">`)
    48 		`" version="1.0">`)
    49 	ch := make(chan interface{})
    49 	ch := make(chan interface{})
    50 	go readXml(r, ch, make(map[xml.Name]reflect.Type))
    50 	go recvXml(r, ch, make(map[xml.Name]reflect.Type))
    51 	x := <-ch
    51 	x := <-ch
    52 	ss, ok := x.(*stream)
    52 	ss, ok := x.(*stream)
    53 	if !ok {
    53 	if !ok {
    54 		t.Fatalf("not stream: %v", reflect.TypeOf(x))
    54 		t.Fatalf("not stream: %v", reflect.TypeOf(x))
    55 	}
    55 	}
    64 	ch := make(chan interface{})
    64 	ch := make(chan interface{})
    65 	var wg sync.WaitGroup
    65 	var wg sync.WaitGroup
    66 	wg.Add(1)
    66 	wg.Add(1)
    67 	go func() {
    67 	go func() {
    68 		defer wg.Done()
    68 		defer wg.Done()
    69 		writeXml(w, ch)
    69 		sendXml(w, ch)
    70 	}()
    70 	}()
    71 	ch <- obj
    71 	ch <- obj
    72 	close(ch)
    72 	close(ch)
    73 	wg.Wait()
    73 	wg.Wait()
    74 	return w.String()
    74 	return w.String()