Пример #1
0
func TestFirewallList(t *testing.T) {
	client, err := clients.NewNetworkV2Client()
	if err != nil {
		t.Fatalf("Unable to create a network client: %v", err)
	}

	allPages, err := firewalls.List(client, nil).AllPages()
	if err != nil {
		t.Fatalf("Unable to list firewalls: %v", err)
	}

	allFirewalls, err := firewalls.ExtractFirewalls(allPages)
	if err != nil {
		t.Fatalf("Unable to extract firewalls: %v", err)
	}

	for _, firewall := range allFirewalls {
		PrintFirewall(t, &firewall)
	}
}
Пример #2
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/v2.0/fw/firewalls", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
   "firewalls":[
        {
           "status": "ACTIVE",
           "name": "fw1",
           "admin_state_up": false,
           "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b",
           "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e28a",
           "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f61",
           "description": "OpenStack firewall 1"
        },
        {
           "status": "PENDING_UPDATE",
           "name": "fw2",
           "admin_state_up": true,
           "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b",
           "firewall_policy_id": "34be8c83-4d42-4dca-a74e-b77fffb8e299",
           "id": "fb5b5315-64f6-4ea3-8e58-981cc37c6f99",
           "description": "OpenStack firewall 2"
        }
   ]
}
      `)
	})

	count := 0

	firewalls.List(fake.ServiceClient(), firewalls.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := firewalls.ExtractFirewalls(page)
		if err != nil {
			t.Errorf("Failed to extract members: %v", err)
			return false, err
		}

		expected := []firewalls.Firewall{
			{
				Status:       "ACTIVE",
				Name:         "fw1",
				AdminStateUp: false,
				TenantID:     "b4eedccc6fb74fa8a7ad6b08382b852b",
				PolicyID:     "34be8c83-4d42-4dca-a74e-b77fffb8e28a",
				ID:           "fb5b5315-64f6-4ea3-8e58-981cc37c6f61",
				Description:  "OpenStack firewall 1",
			},
			{
				Status:       "PENDING_UPDATE",
				Name:         "fw2",
				AdminStateUp: true,
				TenantID:     "b4eedccc6fb74fa8a7ad6b08382b852b",
				PolicyID:     "34be8c83-4d42-4dca-a74e-b77fffb8e299",
				ID:           "fb5b5315-64f6-4ea3-8e58-981cc37c6f99",
				Description:  "OpenStack firewall 2",
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	if count != 1 {
		t.Errorf("Expected 1 page, got %d", count)
	}
}