File: backend_test.go

package info (click to toggle)
gitlab-workhorse 7.6.0%2Bdebian-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,440 kB
  • sloc: makefile: 233; sh: 161; python: 15
file content (42 lines) | stat: -rw-r--r-- 983 bytes parent folder | download | duplicates (2)
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"
)

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

	for _, example := range failures {
		if _, err := parseAuthBackend(example); err == nil {
			t.Errorf("error expected for %q", example)
		}
	}

	successes := []struct{ input, host, scheme string }{
		{"http://localhost:8080", "localhost:8080", "http"},
		{"localhost:3000", "localhost:3000", "http"},
		{"http://localhost", "localhost", "http"},
		{"localhost", "localhost", "http"},
	}

	for _, example := range successes {
		result, err := parseAuthBackend(example.input)
		if err != nil {
			t.Errorf("parse %q: %v", example.input, err)
			break
		}

		if result.Host != example.host {
			t.Errorf("example %q: expected %q, got %q", example.input, example.host, result.Host)
		}

		if result.Scheme != example.scheme {
			t.Errorf("example %q: expected %q, got %q", example.input, example.scheme, result.Scheme)
		}
	}
}