File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (36 lines) | stat: -rw-r--r-- 1,045 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
package testing

import (
	"encoding/base64"
	"testing"

	"github.com/gophercloud/gophercloud/openstack/baremetal/httpbasic"
	th "github.com/gophercloud/gophercloud/testhelper"
)

func TestHttpBasic(t *testing.T) {
	httpClient, err := httpbasic.NewBareMetalHTTPBasic(httpbasic.EndpointOpts{
		IronicEndpoint:     "http://ironic:6385/v1",
		IronicUser:         "myUser",
		IronicUserPassword: "myPasswd",
	})
	th.AssertNoErr(t, err)
	encToken := base64.StdEncoding.EncodeToString([]byte("myUser:myPasswd"))
	headerValue := "Basic " + encToken

	th.AssertEquals(t, headerValue, httpClient.MoreHeaders["Authorization"])

	errTest1, err := httpbasic.NewBareMetalHTTPBasic(httpbasic.EndpointOpts{
		IronicEndpoint: "http://ironic:6385/v1",
	})
	_ = errTest1
	th.AssertEquals(t, "User and Password are required", err.Error())

	errTest2, err := httpbasic.NewBareMetalHTTPBasic(httpbasic.EndpointOpts{
		IronicUser:         "myUser",
		IronicUserPassword: "myPasswd",
	})
	_ = errTest2
	th.AssertEquals(t, "IronicEndpoint is required", err.Error())

}