File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 10,224 kB
  • sloc: sh: 125; makefile: 21
file content (34 lines) | stat: -rw-r--r-- 1,155 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
package testing

import (
	"encoding/base64"
	"testing"

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

func TestNoAuth(t *testing.T) {
	httpClient, err := httpbasic.NewBareMetalIntrospectionHTTPBasic(httpbasic.EndpointOpts{
		IronicInspectorEndpoint:     "http://ironic:5050/v1",
		IronicInspectorUser:         "myUser",
		IronicInspectorUserPassword: "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.NewBareMetalIntrospectionHTTPBasic(httpbasic.EndpointOpts{
		IronicInspectorEndpoint: "http://ironic:5050/v1",
	})
	_ = errTest1
	th.AssertEquals(t, "User and Password are required", err.Error())

	errTest2, err := httpbasic.NewBareMetalIntrospectionHTTPBasic(httpbasic.EndpointOpts{
		IronicInspectorUser:         "myUser",
		IronicInspectorUserPassword: "myPasswd",
	})
	_ = errTest2
	th.AssertEquals(t, "IronicInspectorEndpoint is required", err.Error())
}