summaryrefslogtreecommitdiff
path: root/workhorse/backend_test.go
blob: 8b62287fee4e68aff956f60ba1242cb7c0053191 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
package main

import (
	"testing"

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

func TestParseAuthBackendFailure(t *testing.T) {
	failures := []string{
		"",
		"ftp://localhost",
		"gopher://example.com",
	}

	for _, example := range failures {
		t.Run(example, func(t *testing.T) {
			_, err := parseAuthBackend(example)
			require.Error(t, err)
		})
	}
}

func TestParseAuthBackend(t *testing.T) {
	successes := []struct{ input, host, scheme string }{
		{"http://localhost:8080", "localhost:8080", "http"},
		{"localhost:3000", "localhost:3000", "http"},
		{"http://localhost", "localhost", "http"},
		{"localhost", "localhost", "http"},
		{"https://localhost", "localhost", "https"},
	}

	for _, example := range successes {
		t.Run(example.input, func(t *testing.T) {
			result, err := parseAuthBackend(example.input)
			require.NoError(t, err)

			require.Equal(t, example.host, result.Host, "host")
			require.Equal(t, example.scheme, result.Scheme, "scheme")
		})
	}
}