blob: bc6a2c70ea75ef02868c8936f8ae2216a7ee3367 [file] [log] [blame]
Jamie Hannaford2d480372014-10-22 10:47:09 +02001// +build acceptance compute flavors
Ash Wilsonfd566482014-09-23 15:47:35 -04002
3package v2
4
5import (
6 "testing"
7
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
Ash Wilsonfd566482014-09-23 15:47:35 -04009)
10
Joe Topjian8349dfa2016-07-24 02:11:27 +000011func TestFlavorsList(t *testing.T) {
Ash Wilsonfd566482014-09-23 15:47:35 -040012 client, err := newClient()
13 if err != nil {
14 t.Fatalf("Unable to create a compute client: %v", err)
15 }
16
Joe Topjian8349dfa2016-07-24 02:11:27 +000017 allPages, err := flavors.ListDetail(client, nil).AllPages()
18 if err != nil {
19 t.Fatalf("Unable to retrieve flavors: %v", err)
20 }
Ash Wilsonfd566482014-09-23 15:47:35 -040021
Joe Topjian8349dfa2016-07-24 02:11:27 +000022 allFlavors, err := flavors.ExtractFlavors(allPages)
23 if err != nil {
24 t.Fatalf("Unable to extract flavor results: %v", err)
25 }
Ash Wilsonfd566482014-09-23 15:47:35 -040026
Joe Topjian8349dfa2016-07-24 02:11:27 +000027 for _, flavor := range allFlavors {
28 printFlavor(t, &flavor)
29 }
Ash Wilsonfd566482014-09-23 15:47:35 -040030}
31
Joe Topjian8349dfa2016-07-24 02:11:27 +000032func TestFlavorsGet(t *testing.T) {
Ash Wilsonfd566482014-09-23 15:47:35 -040033 client, err := newClient()
34 if err != nil {
35 t.Fatalf("Unable to create a compute client: %v", err)
36 }
37
38 choices, err := ComputeChoicesFromEnv()
39 if err != nil {
40 t.Fatal(err)
41 }
42
Ash Wilson89734d02014-09-25 13:50:08 -040043 flavor, err := flavors.Get(client, choices.FlavorID).Extract()
Ash Wilsonfd566482014-09-23 15:47:35 -040044 if err != nil {
45 t.Fatalf("Unable to get flavor information: %v", err)
46 }
Ash Wilsonfd566482014-09-23 15:47:35 -040047
Joe Topjian8349dfa2016-07-24 02:11:27 +000048 printFlavor(t, flavor)
49}
50
51func printFlavor(t *testing.T, flavor *flavors.Flavor) {
52 t.Logf("ID: %s", flavor.ID)
53 t.Logf("Name: %s", flavor.Name)
54 t.Logf("RAM: %d", flavor.RAM)
55 t.Logf("Disk: %d", flavor.Disk)
56 t.Logf("Swap: %d", flavor.Swap)
57 t.Logf("RxTxFactor: %f", flavor.RxTxFactor)
Ash Wilsonfd566482014-09-23 15:47:35 -040058}