From 12164cc8054b69ccab3c2b8914ddff5a94cb65d3 Mon Sep 17 00:00:00 2001 From: Marvin Preuss Date: Tue, 16 Nov 2021 15:22:39 +0100 Subject: [PATCH] test: tests for NewTarget --- main_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 main_test.go 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) + }) + } +}