~samwhited/xmpp

6c549873aadd65988101eca89ab91b7c8d08db84 — Sam Whited 3 years ago 6ab0fec xep0199_ping
XEP-0199: XMPP Ping
2 files changed, 45 insertions(+), 0 deletions(-)

A ping/ping.go
A ping/ping_test.go
A ping/ping.go => ping/ping.go +21 -0
@@ 0,0 1,21 @@
// Copyright 2016 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

// Package ping implements XEP-0199: XMPP Ping.
package ping

import (
	"mellium.im/xmpp"
)

// BUG(ssw): This package does not currently provide a means of registering a
//           disco#info feature or a response handler.

const ns = `urn:xmpp:ping`

type Ping struct {
	xmpp.IQ

	Ping struct{} `xml:"urn:xmpp:ping ping"`
}

A ping/ping_test.go => ping/ping_test.go +24 -0
@@ 0,0 1,24 @@
// Copyright 2016 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

package ping

import (
	"encoding/xml"
	"testing"
)

func TestMarshal(t *testing.T) {
	p := Ping{}
	b, err := xml.Marshal(p)
	if err != nil {
		t.Fatal(err)
	}
	out := `<iq id="" type="get"><ping xmlns="urn:xmpp:ping"></ping></iq>`
	// TODO: This is probably flakey because the order of the id/type attributes
	//       isn't guaranteed.
	if string(b) != out {
		t.Errorf("Marshaled invalid ping, want=`%s`, got=`%s`", out, b)
	}
}