/cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/networks_test.go

https://bitbucket.org/enterstudiosbiz/origin · Go · 65 lines · 49 code · 14 blank · 2 comment · 16 complexity · 741114b7223a96dc57dc90a766c38997 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/networks"
  8. )
  9. func TestNetworksList(t *testing.T) {
  10. client, err := clients.NewNetworkV2Client()
  11. if err != nil {
  12. t.Fatalf("Unable to create a network client: %v", err)
  13. }
  14. allPages, err := networks.List(client, nil).AllPages()
  15. if err != nil {
  16. t.Fatalf("Unable to list networks: %v", err)
  17. }
  18. allNetworks, err := networks.ExtractNetworks(allPages)
  19. if err != nil {
  20. t.Fatalf("Unable to extract networks: %v", err)
  21. }
  22. for _, network := range allNetworks {
  23. tools.PrintResource(t, network)
  24. }
  25. }
  26. func TestNetworksCRUD(t *testing.T) {
  27. client, err := clients.NewNetworkV2Client()
  28. if err != nil {
  29. t.Fatalf("Unable to create a network client: %v", err)
  30. }
  31. // Create a network
  32. network, err := CreateNetwork(t, client)
  33. if err != nil {
  34. t.Fatalf("Unable to create network: %v", err)
  35. }
  36. defer DeleteNetwork(t, client, network.ID)
  37. tools.PrintResource(t, network)
  38. newName := tools.RandomString("TESTACC-", 8)
  39. updateOpts := &networks.UpdateOpts{
  40. Name: newName,
  41. }
  42. _, err = networks.Update(client, network.ID, updateOpts).Extract()
  43. if err != nil {
  44. t.Fatalf("Unable to update network: %v", err)
  45. }
  46. newNetwork, err := networks.Get(client, network.ID).Extract()
  47. if err != nil {
  48. t.Fatalf("Unable to retrieve network: %v", err)
  49. }
  50. tools.PrintResource(t, newNetwork)
  51. }