PageRenderTime 52ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networks_test.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 73 lines | 55 code | 16 blank | 2 comment | 16 complexity | 9ed2d52f8182e96a15d6e99ed6f298a0 MD5 | raw file
  1. // +build acceptance networking
  2. package v2
  3. import (
  4. "testing"
  5. "github.com/gophercloud/gophercloud/acceptance/clients"
  6. "github.com/gophercloud/gophercloud/acceptance/tools"
  7. "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity"
  8. "github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
  9. )
  10. func TestNetworksList(t *testing.T) {
  11. client, err := clients.NewNetworkV2Client()
  12. if err != nil {
  13. t.Fatalf("Unable to create a network client: %v", err)
  14. }
  15. type networkWithExt struct {
  16. networks.Network
  17. portsecurity.PortSecurityExt
  18. }
  19. var allNetworks []networkWithExt
  20. allPages, err := networks.List(client, nil).AllPages()
  21. if err != nil {
  22. t.Fatalf("Unable to list networks: %v", err)
  23. }
  24. err = networks.ExtractNetworksInto(allPages, &allNetworks)
  25. if err != nil {
  26. t.Fatalf("Unable to extract networks: %v", err)
  27. }
  28. for _, network := range allNetworks {
  29. tools.PrintResource(t, network)
  30. }
  31. }
  32. func TestNetworksCRUD(t *testing.T) {
  33. client, err := clients.NewNetworkV2Client()
  34. if err != nil {
  35. t.Fatalf("Unable to create a network client: %v", err)
  36. }
  37. // Create a network
  38. network, err := CreateNetwork(t, client)
  39. if err != nil {
  40. t.Fatalf("Unable to create network: %v", err)
  41. }
  42. defer DeleteNetwork(t, client, network.ID)
  43. tools.PrintResource(t, network)
  44. newName := tools.RandomString("TESTACC-", 8)
  45. updateOpts := &networks.UpdateOpts{
  46. Name: newName,
  47. }
  48. _, err = networks.Update(client, network.ID, updateOpts).Extract()
  49. if err != nil {
  50. t.Fatalf("Unable to update network: %v", err)
  51. }
  52. newNetwork, err := networks.Get(client, network.ID).Extract()
  53. if err != nil {
  54. t.Fatalf("Unable to retrieve network: %v", err)
  55. }
  56. tools.PrintResource(t, newNetwork)
  57. }