mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-23 19:12:00 -08:00
parent
2cdda48467
commit
005c8823d9
@ -4,6 +4,7 @@ import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@ -211,7 +212,7 @@ func (c *Client) Send(packet stanza.Packet) error {
|
||||
return errors.New("cannot marshal packet " + err.Error())
|
||||
}
|
||||
|
||||
return c.sendWithLogger(string(data))
|
||||
return c.sendWithWriter(c.Session.streamLogger, data)
|
||||
}
|
||||
|
||||
// SendRaw sends an XMPP stanza as a string to the server.
|
||||
@ -224,12 +225,12 @@ func (c *Client) SendRaw(packet string) error {
|
||||
return errors.New("client is not connected")
|
||||
}
|
||||
|
||||
return c.sendWithLogger(packet)
|
||||
return c.sendWithWriter(c.Session.streamLogger, []byte(packet))
|
||||
}
|
||||
|
||||
func (c *Client) sendWithLogger(packet string) error {
|
||||
func (c *Client) sendWithWriter(writer io.Writer, packet []byte) error {
|
||||
var err error
|
||||
_, err = fmt.Fprintf(c.Session.streamLogger, packet)
|
||||
_, err = writer.Write(packet)
|
||||
return err
|
||||
}
|
||||
|
||||
|
19
client_internal_test.go
Normal file
19
client_internal_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClient_Send(t *testing.T) {
|
||||
buffer := bytes.NewBufferString("")
|
||||
client := Client{}
|
||||
data := []byte("https://da.wikipedia.org/wiki/J%C3%A6vnd%C3%B8gn")
|
||||
if err := client.sendWithWriter(buffer, data); err != nil {
|
||||
t.Errorf("Writing failed: %v", err)
|
||||
}
|
||||
|
||||
if buffer.String() != string(data) {
|
||||
t.Errorf("Incorrect value sent to buffer: '%s'", buffer.String())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user