github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/httpbasic/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"encoding/base64"
     5  	"testing"
     6  
     7  	"github.com/gophercloud/gophercloud/openstack/baremetal/httpbasic"
     8  	th "github.com/gophercloud/gophercloud/testhelper"
     9  )
    10  
    11  func TestHttpBasic(t *testing.T) {
    12  	httpClient, err := httpbasic.NewBareMetalHTTPBasic(httpbasic.EndpointOpts{
    13  		IronicEndpoint:     "http://ironic:6385/v1",
    14  		IronicUser:         "myUser",
    15  		IronicUserPassword: "myPasswd",
    16  	})
    17  	th.AssertNoErr(t, err)
    18  	encToken := base64.StdEncoding.EncodeToString([]byte("myUser:myPasswd"))
    19  	headerValue := "Basic " + encToken
    20  
    21  	th.AssertEquals(t, headerValue, httpClient.MoreHeaders["Authorization"])
    22  
    23  	errTest1, err := httpbasic.NewBareMetalHTTPBasic(httpbasic.EndpointOpts{
    24  		IronicEndpoint: "http://ironic:6385/v1",
    25  	})
    26  	_ = errTest1
    27  	th.AssertEquals(t, "User and Password are required", err.Error())
    28  
    29  	errTest2, err := httpbasic.NewBareMetalHTTPBasic(httpbasic.EndpointOpts{
    30  		IronicUser:         "myUser",
    31  		IronicUserPassword: "myPasswd",
    32  	})
    33  	_ = errTest2
    34  	th.AssertEquals(t, "IronicEndpoint is required", err.Error())
    35  
    36  }