Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(147)

Side by Side Diff: environs/ec2/live_test.go

Issue 6849044: environs/jujutest: simplify interface
Patch Set: environs/jujutest: simplify interface Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « environs/dummy/environs_test.go ('k') | environs/ec2/local_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package ec2_test 1 package ec2_test
2 2
3 import ( 3 import (
4 "crypto/rand" 4 "crypto/rand"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "io/ioutil" 7 "io/ioutil"
8 amzec2 "launchpad.net/goamz/ec2" 8 amzec2 "launchpad.net/goamz/ec2"
9 . "launchpad.net/gocheck" 9 . "launchpad.net/gocheck"
10 "launchpad.net/juju-core/environs" 10 "launchpad.net/juju-core/environs"
11 "launchpad.net/juju-core/environs/config"
11 "launchpad.net/juju-core/environs/ec2" 12 "launchpad.net/juju-core/environs/ec2"
12 "launchpad.net/juju-core/environs/jujutest" 13 "launchpad.net/juju-core/environs/jujutest"
13 "launchpad.net/juju-core/juju/testing" 14 "launchpad.net/juju-core/juju/testing"
14 coretesting "launchpad.net/juju-core/testing" 15 coretesting "launchpad.net/juju-core/testing"
15 "strings" 16 "strings"
16 ) 17 )
17 18
18 // amazonConfig holds the environments configuration 19 // uniqueName is generated afresh for every test run, so that
19 // for running the amazon EC2 integration tests.
20 //
21 // This is missing keys for security reasons; set the following environment vari ables
22 // to make the Amazon testing work:
23 // access-key: $AWS_ACCESS_KEY_ID
24 // secret-key: $AWS_SECRET_ACCESS_KEY
25 var amazonConfig = fmt.Sprintf(`
26 environments:
27 sample-%s:
28 type: ec2
29 control-bucket: 'juju-test-%s'
30 public-bucket: 'juju-public-test-%s'
31 admin-secret: 'for real'
32 `, uniqueName, uniqueName, uniqueName)
33
34 // uniqueName is generated afresh for every test, so that
35 // we are not polluted by previous test state. 20 // we are not polluted by previous test state.
36 var uniqueName = randomName() 21 var uniqueName = randomName()
37 22
38 func randomName() string { 23 func randomName() string {
39 buf := make([]byte, 8) 24 buf := make([]byte, 8)
40 _, err := io.ReadFull(rand.Reader, buf) 25 _, err := io.ReadFull(rand.Reader, buf)
41 if err != nil { 26 if err != nil {
42 panic(fmt.Sprintf("error from crypto rand: %v", err)) 27 panic(fmt.Sprintf("error from crypto rand: %v", err))
43 } 28 }
44 return fmt.Sprintf("%x", buf) 29 return fmt.Sprintf("%x", buf)
45 } 30 }
46 31
47 func registerAmazonTests() { 32 func registerAmazonTests() {
48 » envs, err := environs.ReadEnvironsBytes([]byte(amazonConfig)) 33 » // The following attributes hold the environment configuration
34 » // for running the amazon EC2 integration tests.
35 » //
36 » // This is missing keys for security reasons; set the following
37 » // environment variables to make the Amazon testing work:
38 » // access-key: $AWS_ACCESS_KEY_ID
39 » // secret-key: $AWS_SECRET_ACCESS_KEY
40 » cfg, err := config.New(map[string]interface{}{
41 » » "name": "sample-" + uniqueName,
42 » » "type": "ec2",
43 » » "control-bucket": "juju-test-" + uniqueName,
44 » » "public-bucket": "juju-public-test-" + uniqueName,
45 » » "admin-secret": "for real",
46 » })
49 if err != nil { 47 if err != nil {
50 » » panic(fmt.Errorf("cannot parse amazon tests config data: %v", er r)) 48 » » panic(fmt.Errorf("cannot create config: %v", err))
51 } 49 }
52 » for _, name := range envs.Names() { 50 » Suite(&LiveTests{
53 » » Suite(&LiveTests{ 51 » » LiveTests: jujutest.LiveTests{
54 » » » LiveTests: jujutest.LiveTests{ 52 » » » Config: cfg,
55 » » » » Environs: envs, 53 » » » Attempt: *ec2.ShortAttempt,
56 » » » » Name: name, 54 » » » CanOpenState: true,
57 » » » » Attempt: *ec2.ShortAttempt, 55 » » » HasProvisioner: true,
58 » » » » CanOpenState: true, 56 » » },
59 » » » » HasProvisioner: true, 57 » })
60 » » » },
61 » » })
62 » }
63 } 58 }
64 59
65 // LiveTests contains tests that can be run against the Amazon servers. 60 // LiveTests contains tests that can be run against the Amazon servers.
66 // Each test runs using the same ec2 connection. 61 // Each test runs using the same ec2 connection.
67 type LiveTests struct { 62 type LiveTests struct {
68 coretesting.LoggingSuite 63 coretesting.LoggingSuite
69 jujutest.LiveTests 64 jujutest.LiveTests
70 } 65 }
71 66
72 func (t *LiveTests) SetUpSuite(c *C) { 67 func (t *LiveTests) SetUpSuite(c *C) {
73 t.LoggingSuite.SetUpSuite(c) 68 t.LoggingSuite.SetUpSuite(c)
74 » e, err := t.Environs.Open("") 69 » e, err := environs.New(t.Config)
75 c.Assert(err, IsNil) 70 c.Assert(err, IsNil)
76 // Put some fake tools in place so that tests that are simply 71 // Put some fake tools in place so that tests that are simply
77 // starting instances without any need to check if those instances 72 // starting instances without any need to check if those instances
78 // are running will find them in the public bucket. 73 // are running will find them in the public bucket.
79 putFakeTools(c, e.PublicStorage().(environs.Storage)) 74 putFakeTools(c, e.PublicStorage().(environs.Storage))
80 t.LiveTests.SetUpSuite(c) 75 t.LiveTests.SetUpSuite(c)
81 } 76 }
82 77
83 func (t *LiveTests) TearDownSuite(c *C) { 78 func (t *LiveTests) TearDownSuite(c *C) {
84 if t.Env == nil { 79 if t.Env == nil {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 391 }
397 392
398 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool { 393 func hasSecurityGroup(r amzec2.Reservation, g amzec2.SecurityGroup) bool {
399 for _, rg := range r.SecurityGroups { 394 for _, rg := range r.SecurityGroups {
400 if rg.Id == g.Id { 395 if rg.Id == g.Id {
401 return true 396 return true
402 } 397 }
403 } 398 }
404 return false 399 return false
405 } 400 }
OLDNEW
« no previous file with comments | « environs/dummy/environs_test.go ('k') | environs/ec2/local_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b