diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..005a2ae --- /dev/null +++ b/main_test.go @@ -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) + }) + } +}