~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/goose.v1/nova/nova_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package nova_test
 
2
 
 
3
import (
 
4
        "flag"
 
5
        "reflect"
 
6
        "testing"
 
7
 
 
8
        gc "gopkg.in/check.v1"
 
9
 
 
10
        "gopkg.in/goose.v1/identity"
 
11
)
 
12
 
 
13
// imageDetails specify parameters used to start a test machine for the live tests.
 
14
type imageDetails struct {
 
15
        flavor  string
 
16
        imageId string
 
17
        vendor  string
 
18
}
 
19
 
 
20
// Out-of-the-box, we support live testing using Canonistack or HP Cloud.
 
21
var testConstraints = map[string]imageDetails{
 
22
        "canonistack": {
 
23
                flavor: "m1.tiny", imageId: "f2ca48ce-30d5-4f1f-9075-12e64510368d"},
 
24
        "hpcloud": {
 
25
                flavor: "standard.xsmall", imageId: "81078"},
 
26
}
 
27
 
 
28
var live = flag.Bool("live", false, "Include live OpenStack tests")
 
29
var vendor = flag.String("vendor", "", "The Openstack vendor to test against")
 
30
var imageId = flag.String("image", "", "The image id for which a test service is to be started")
 
31
var flavor = flag.String("flavor", "", "The flavor of the test service")
 
32
 
 
33
func Test(t *testing.T) {
 
34
        if *live {
 
35
                // We can either specify a vendor, or imageId and flavor separately.
 
36
                var testImageDetails imageDetails
 
37
                if *vendor != "" {
 
38
                        var ok bool
 
39
                        if testImageDetails, ok = testConstraints[*vendor]; !ok {
 
40
                                keys := reflect.ValueOf(testConstraints).MapKeys()
 
41
                                t.Fatalf("Unknown vendor %s. Must be one of %s", *vendor, keys)
 
42
                        }
 
43
                        testImageDetails.vendor = *vendor
 
44
                } else {
 
45
                        if *imageId == "" {
 
46
                                t.Fatalf("Must specify image id to use for test instance, "+
 
47
                                        "eg %s for Canonistack", "-image c876e5fe-abb0-41f0-8f29-f0b47481f523")
 
48
                        }
 
49
                        if *flavor == "" {
 
50
                                t.Fatalf("Must specify flavor to use for test instance, "+
 
51
                                        "eg %s for Canonistack", "-flavor m1.tiny")
 
52
                        }
 
53
                        testImageDetails = imageDetails{*flavor, *imageId, ""}
 
54
                }
 
55
                cred, err := identity.CompleteCredentialsFromEnv()
 
56
                if err != nil {
 
57
                        t.Fatalf("Error setting up test suite: %s", err.Error())
 
58
                }
 
59
                registerOpenStackTests(cred, testImageDetails)
 
60
        }
 
61
        registerLocalTests()
 
62
        gc.TestingT(t)
 
63
}