blob: 8e4813f392658558b412d7befbfe7a73ee3ecbc1 [file] [log] [blame]
package nodes
import (
"testing"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)
const (
lbID = 12345
nodeID = 67890
)
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockListResponse(t, lbID)
count := 0
err := List(client.ServiceClient(), lbID, nil).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractNodes(page)
th.AssertNoErr(t, err)
expected := []Node{
Node{
ID: 410,
Address: "10.1.1.1",
Port: 80,
Condition: ENABLED,
Status: ONLINE,
Weight: 3,
Type: PRIMARY,
},
Node{
ID: 411,
Address: "10.1.1.2",
Port: 80,
Condition: ENABLED,
Status: ONLINE,
Weight: 8,
Type: SECONDARY,
},
}
th.CheckDeepEquals(t, expected, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, 1, count)
}
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
mockCreateResponse(t, lbID)
opts := CreateOpts{
CreateOpt{
Address: "10.2.2.3",
Port: 80,
Condition: ENABLED,
Type: PRIMARY,
},
CreateOpt{
Address: "10.2.2.4",
Port: 81,
Condition: ENABLED,
Type: SECONDARY,
},
}
page := Create(client.ServiceClient(), lbID, opts)
actual, err := page.ExtractNodes()
th.AssertNoErr(t, err)
expected := []Node{
Node{
ID: 185,
Address: "10.2.2.3",
Port: 80,
Condition: ENABLED,
Status: ONLINE,
Weight: 1,
Type: PRIMARY,
},
Node{
ID: 186,
Address: "10.2.2.4",
Port: 81,
Condition: ENABLED,
Status: ONLINE,
Weight: 1,
Type: SECONDARY,
},
}
th.CheckDeepEquals(t, expected, actual)
}