Codebase list golang-github-go-openapi-swag / 9048c7a1-8c73-4f3e-9be8-fcf4e0522d37/main net_test.go
9048c7a1-8c73-4f3e-9be8-fcf4e0522d37/main

Tree @9048c7a1-8c73-4f3e-9be8-fcf4e0522d37/main (Download .tar.gz)

net_test.go @9048c7a1-8c73-4f3e-9be8-fcf4e0522d37/mainraw · history · blame

package swag

import (
	"testing"

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

func TestSplitHostPort(t *testing.T) {
	data := []struct {
		Input string
		Host  string
		Port  int
		Err   bool
	}{
		{"localhost:3933", "localhost", 3933, false},
		{"localhost:yellow", "", -1, true},
		{"localhost", "", -1, true},
		{"localhost:", "", -1, true},
		{"localhost:3933", "localhost", 3933, false},
	}

	for _, e := range data {
		h, p, err := SplitHostPort(e.Input)
		if (!e.Err && assert.NoError(t, err)) || (e.Err && assert.Error(t, err)) {
			assert.Equal(t, e.Host, h)
			assert.Equal(t, e.Port, p)
		}
	}
}