github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/objectstorage/v1/swauth/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/objectstorage/v1/swauth"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  )
    11  
    12  func TestAuth(t *testing.T) {
    13  	authOpts := swauth.AuthOpts{
    14  		User: "test:tester",
    15  		Key:  "testing",
    16  	}
    17  
    18  	th.SetupHTTP()
    19  	defer th.TeardownHTTP()
    20  	HandleAuthSuccessfully(t, authOpts)
    21  
    22  	providerClient, err := openstack.NewClient(th.Endpoint())
    23  	th.AssertNoErr(t, err)
    24  
    25  	swiftClient, err := swauth.NewObjectStorageV1(context.TODO(), providerClient, authOpts)
    26  	th.AssertNoErr(t, err)
    27  	th.AssertEquals(t, AuthResult.Token, swiftClient.TokenID)
    28  }
    29  
    30  func TestBadAuth(t *testing.T) {
    31  	authOpts := swauth.AuthOpts{}
    32  	_, err := authOpts.ToAuthOptsMap()
    33  	if err == nil {
    34  		t.Fatalf("Expected an error due to missing auth options")
    35  	}
    36  }