test: tests for NewTarget
This commit is contained in:
parent
42756d7340
commit
12164cc805
48
main_test.go
Normal file
48
main_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package main //nolint:testpackage
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewTarget(t *testing.T) {
|
||||
require := require.New(t)
|
||||
t.Parallel()
|
||||
|
||||
tables := []struct {
|
||||
name string
|
||||
t string
|
||||
expected Target
|
||||
err error
|
||||
}{
|
||||
{
|
||||
"001",
|
||||
"foobar.tld",
|
||||
Target{"foobar.tld", 5201},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"002",
|
||||
"foobar.tld:1234",
|
||||
Target{"foobar.tld", 1234},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"003",
|
||||
"foobar:foobar:foobar",
|
||||
Target{},
|
||||
ErrCouldNotDetermineTarget,
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
table := table
|
||||
t.Run(table.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
trgt, err := NewTarget(table.t)
|
||||
require.ErrorIs(err, table.err)
|
||||
require.Equal(table.expected, trgt)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user