1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-23 17:21:50 +02:00
lego/providers/dns/dynu/internal/auth_test.go

41 lines
839 B
Go
Raw Normal View History

2020-03-10 13:31:33 +02:00
package internal
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewTokenTransport_success(t *testing.T) {
apiKey := "api"
transport, err := NewTokenTransport(apiKey)
require.NoError(t, err)
assert.NotNil(t, transport)
}
func TestNewTokenTransport_missing_credentials(t *testing.T) {
apiKey := ""
transport, err := NewTokenTransport(apiKey)
require.Error(t, err)
assert.Nil(t, transport)
}
func TestTokenTransport_RoundTrip(t *testing.T) {
apiKey := "api"
transport, err := NewTokenTransport(apiKey)
require.NoError(t, err)
req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)
resp, err := transport.RoundTrip(req)
require.NoError(t, err)
assert.Equal(t, "api", resp.Request.Header.Get(apiKeyHeader))
}