File: hostmaybeport_test.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 836 kB
  • sloc: makefile: 4
file content (30 lines) | stat: -rw-r--r-- 729 bytes parent folder | download
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
package missinggo

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSplitHostMaybePortNoPort(t *testing.T) {
	hmp := SplitHostMaybePort("some.domain")
	assert.Equal(t, "some.domain", hmp.Host)
	assert.True(t, hmp.NoPort)
	assert.NoError(t, hmp.Err)
}

func TestSplitHostMaybePortPort(t *testing.T) {
	hmp := SplitHostMaybePort("some.domain:123")
	assert.Equal(t, "some.domain", hmp.Host)
	assert.Equal(t, 123, hmp.Port)
	assert.False(t, hmp.NoPort)
	assert.NoError(t, hmp.Err)
}

func TestSplitHostMaybePortBadPort(t *testing.T) {
	hmp := SplitHostMaybePort("some.domain:wat")
	assert.Equal(t, "some.domain", hmp.Host)
	assert.Equal(t, -1, hmp.Port)
	assert.False(t, hmp.NoPort)
	assert.Error(t, hmp.Err)
}