github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/acceptance/openstack/networking/v2/peering/peerings_test.go (about)

     1  package peering
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/huaweicloud/golangsdk/acceptance/clients"
     7  	"github.com/huaweicloud/golangsdk/acceptance/tools"
     8  	"github.com/huaweicloud/golangsdk/openstack/networking/v2/peerings"
     9  )
    10  
    11  func TestPeeringList(t *testing.T) {
    12  	client, err := clients.NewNetworkV2Client()
    13  	if err != nil {
    14  		t.Fatalf("Unable to create a vpc client: %v", err)
    15  	}
    16  
    17  	listOpts := peerings.ListOpts{}
    18  	peering, err := peerings.List(client, listOpts)
    19  	if err != nil {
    20  		t.Fatalf("Unable to list peerings: %v", err)
    21  	}
    22  	for _, peering := range peering {
    23  		tools.PrintResource(t, peering)
    24  	}
    25  }
    26  
    27  func TestAcceptPeering(t *testing.T) {
    28  
    29  	clientV2, peerClientV2, clientV1, peerClientV1, peeringConn := InitiatePeeringConnCommonTasks(t)
    30  
    31  	// Delete a vpc peering connection
    32  	defer DeletePeeringConnNResources(t, clientV2, clientV1, peerClientV1, peeringConn)
    33  
    34  	peeringConn1, err := peerings.Accept(peerClientV2, peeringConn.ID).ExtractResult()
    35  	if err != nil {
    36  		t.Fatalf("Unable to accept peering request: %v", err)
    37  	}
    38  	tools.PrintResource(t, peeringConn1)
    39  
    40  }
    41  
    42  func TestRejectPeering(t *testing.T) {
    43  
    44  	clientV2, peerClientV2, clientV1, peerClientV1, peeringConn := InitiatePeeringConnCommonTasks(t)
    45  
    46  	// Delete a vpc peering connection
    47  	defer DeletePeeringConnNResources(t, clientV2, clientV1, peerClientV1, peeringConn)
    48  
    49  	peerConn1, err := peerings.Reject(peerClientV2, peeringConn.ID).ExtractResult()
    50  	if err != nil {
    51  		t.Fatalf("Unable to Reject peering request: %v", err)
    52  	}
    53  	tools.PrintResource(t, peerConn1)
    54  
    55  }
    56  
    57  func TestPeeringCRUD(t *testing.T) {
    58  
    59  	clientV2, peerClientV2, clientV1, peerClientV1, peeringConn := InitiatePeeringConnCommonTasks(t)
    60  
    61  	// Delete a vpc peering connection
    62  	defer DeletePeeringConnNResources(t, clientV2, clientV1, peerClientV1, peeringConn)
    63  
    64  	tools.PrintResource(t, peeringConn)
    65  	updateOpts := peerings.UpdateOpts{
    66  		Name: "test2",
    67  	}
    68  
    69  	_, err := peerings.Update(clientV2, peeringConn.ID, updateOpts).Extract()
    70  	if err != nil {
    71  		t.Fatalf("Unable to update vpc peering connection: %v", err)
    72  	}
    73  
    74  	peeringConnGet, err := peerings.Get(peerClientV2, peeringConn.ID).Extract()
    75  	if err != nil {
    76  		t.Fatalf("Unable to retrieve vpc peering connection: %v", err)
    77  	}
    78  
    79  	tools.PrintResource(t, peeringConnGet)
    80  }