File: authentication_test.go

package info (click to toggle)
golang-github-weppos-dnsimple-go 0.0~git20160204.0.65c1ca7-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 144 kB
  • ctags: 147
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,204 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
package dnsimple

import (
	"fmt"
	"testing"
)

func testCredentials(t *testing.T, credentials Credentials, expectedName, expectedValue string) {
	headerName, headerValue := credentials.HttpHeader()
	if headerName != expectedName {
		t.Errorf("Header name: %v, want %v", headerName, expectedName)
	}

	if headerValue != expectedValue {
		t.Errorf("Header value: %v, want %v", headerValue, expectedValue)
	}
}

func TestDomainTokenCredentialsHttpHeader(t *testing.T) {
	domainToken := "domain-token"
	credentials := NewDomainTokenCredentials(domainToken)
	testCredentials(t, credentials, httpHeaderDomainToken, domainToken)
}

func TestHttpBasicCredentialsHttpHeader(t *testing.T) {
	email, password := "email", "password"
	credentials := NewHttpBasicCredentials(email, password)
	expectedHeaderValue := "Basic ZW1haWw6cGFzc3dvcmQ="
	testCredentials(t, credentials, httpHeaderAuthorization, expectedHeaderValue)
}

func TestApiTokenCredentialsHttpHeader(t *testing.T) {
	email, apiToken := "email", "api-token"
	credentials := NewApiTokenCredentials(email, apiToken)
	expectedHeaderValue := fmt.Sprintf("%v:%v", email, apiToken)
	testCredentials(t, credentials, httpHeaderApiToken, expectedHeaderValue)
}