~samwhited/xmpp

ref: 98f0e1cf416d7d6ae371688e229f45fc33e12519 xmpp/dial_test.go -rw-r--r-- 1017 bytes
98f0e1cfSam Whited all: bump dep on mellium.im/xmlstream to v0.13.3 1 year, 10 months 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
// Copyright 2016 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package xmpp

import (
	"strconv"
	"testing"

	"mellium.im/xmpp/jid"
)

func TestDialClientPanicsIfNilContext(t *testing.T) {
	defer func() {
		if r := recover(); r == nil {
			t.Error("Expected Dial to panic when passed a nil context.")
		}
	}()
	DialClient(nil, "tcp", jid.MustParse("feste@shakespeare.lit"))
}

var connTypeTests = [...]struct {
	useTLS bool
	s2s    bool
	svc    string
}{
	0: {useTLS: true, s2s: true, svc: "xmpps-server"},
	1: {useTLS: true, s2s: false, svc: "xmpps-client"},
	2: {useTLS: false, s2s: true, svc: "xmpp-server"},
	3: {useTLS: false, s2s: false, svc: "xmpp-client"},
}

func TestConnType(t *testing.T) {
	for i, tc := range connTypeTests {
		t.Run(strconv.Itoa(i), func(t *testing.T) {
			svc := connType(tc.useTLS, tc.s2s)
			if svc != tc.svc {
				t.Errorf("Wrong conntype value: want=%q, got=%q", tc.svc, svc)
			}
		})
	}
}