xmpp_test.go
changeset 9 4fe926b03827
parent 6 8e425e340ca1
child 22 d6b7b4cbf50d
equal deleted inserted replaced
8:30a7752cf8f7 9:4fe926b03827
    14 )
    14 )
    15 
    15 
    16 func TestReadError(t *testing.T) {
    16 func TestReadError(t *testing.T) {
    17 	r := strings.NewReader(`<stream:error><bad-foo/></stream:error>`)
    17 	r := strings.NewReader(`<stream:error><bad-foo/></stream:error>`)
    18 	ch := make(chan interface{})
    18 	ch := make(chan interface{})
    19 	go readXml(r, ch, false)
    19 	go readXml(r, ch)
    20 	x := <- ch
    20 	x := <- ch
    21 	se, ok := x.(*StreamError)
    21 	se, ok := x.(*StreamError)
    22 	if !ok {
    22 	if !ok {
    23 		t.Fatalf("not StreamError: %v", reflect.TypeOf(x))
    23 		t.Fatalf("not StreamError: %v", reflect.TypeOf(x))
    24 	}
    24 	}
    30 
    30 
    31 	r = strings.NewReader(`<stream:error><bad-foo/>` +
    31 	r = strings.NewReader(`<stream:error><bad-foo/>` +
    32 		`<text xml:lang="en" xmlns="` + nsStreams +
    32 		`<text xml:lang="en" xmlns="` + nsStreams +
    33 		`">Error text</text></stream:error>`)
    33 		`">Error text</text></stream:error>`)
    34 	ch = make(chan interface{})
    34 	ch = make(chan interface{})
    35 	go readXml(r, ch, false)
    35 	go readXml(r, ch)
    36 	x = <- ch
    36 	x = <- ch
    37 	se, ok = x.(*StreamError)
    37 	se, ok = x.(*StreamError)
    38 	if !ok {
    38 	if !ok {
    39 		t.Fatalf("not StreamError: %v", reflect.TypeOf(x))
    39 		t.Fatalf("not StreamError: %v", reflect.TypeOf(x))
    40 	}
    40 	}
    48 	r := strings.NewReader(`<stream:stream to="foo.com" ` +
    48 	r := strings.NewReader(`<stream:stream to="foo.com" ` +
    49 		`from="bar.org" id="42"` +
    49 		`from="bar.org" id="42"` +
    50 		`xmlns="jabber:client" xmlns:stream="` + nsStream +
    50 		`xmlns="jabber:client" xmlns:stream="` + nsStream +
    51 		`" version="1.0">`)
    51 		`" version="1.0">`)
    52 	ch := make(chan interface{})
    52 	ch := make(chan interface{})
    53 	go readXml(r, ch, false)
    53 	go readXml(r, ch)
    54 	x := <- ch
    54 	x := <- ch
    55 	ss, ok := x.(*Stream)
    55 	ss, ok := x.(*Stream)
    56 	if !ok {
    56 	if !ok {
    57 		t.Fatalf("not Stream: %v", reflect.TypeOf(x))
    57 		t.Fatalf("not Stream: %v", reflect.TypeOf(x))
    58 	}
    58 	}
    67 	ch := make(chan interface{})
    67 	ch := make(chan interface{})
    68 	var wg sync.WaitGroup
    68 	var wg sync.WaitGroup
    69 	wg.Add(1)
    69 	wg.Add(1)
    70 	go func() {
    70 	go func() {
    71 		defer wg.Done()
    71 		defer wg.Done()
    72 		writeXml(w, ch, true)
    72 		writeXml(w, ch)
    73 	}()
    73 	}()
    74 	ch <- obj
    74 	ch <- obj
    75 	close(ch)
    75 	close(ch)
    76 	wg.Wait()
    76 	wg.Wait()
    77 	return w.String()
    77 	return w.String()