~samwhited/xmpp

xmpp/xtime/integration_test.go -rw-r--r-- 1.5 KiB
c9743d9fSam Whited docs: update changelog to include deprecations 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2020 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

//go:build integration
// +build integration

package xtime_test

import (
	"context"
	"crypto/tls"
	"testing"
	"time"

	"mellium.im/sasl"
	"mellium.im/xmpp"
	"mellium.im/xmpp/internal/integration"
	"mellium.im/xmpp/internal/integration/prosody"
	"mellium.im/xmpp/xtime"
)

func TestIntegrationRequestTime(t *testing.T) {
	prosodyRun := prosody.Test(context.TODO(), t,
		integration.Log(),
		prosody.ListenC2S(),
	)
	prosodyRun(integrationRequestTime)

	// See: https://github.com/processone/ejabberd/issues/3454
	//
	// ejabberdRun := ejabberd.Test(context.TODO(), t,
	// 	integration.Log(),
	// 	ejabberd.ListenC2S(),
	// )
	// ejabberdRun(integrationRequestTime)
}

func integrationRequestTime(ctx context.Context, t *testing.T, cmd *integration.Cmd) {
	j, pass := cmd.User()
	session, err := cmd.DialClient(ctx, j, t,
		xmpp.StartTLS(&tls.Config{
			InsecureSkipVerify: true,
		}),
		xmpp.SASL("", pass, sasl.Plain),
		xmpp.BindResource(),
	)
	if err != nil {
		t.Fatalf("error connecting: %v", err)
	}
	go func() {
		err := session.Serve(nil)
		if err != nil {
			t.Logf("error from serve: %v", err)
		}
	}()
	tt, err := xtime.Get(ctx, session, session.RemoteAddr())
	if err != nil {
		t.Errorf("error getting time: %v", err)
	}
	if now := time.Now().UTC().Format(time.RFC3339); tt.Format(time.RFC3339) != now {
		t.Errorf("wrong time: want=%v, got=%v", now, tt)
	}
}