// Communicate with all EC2 endpoints to see if they are alive. func (s *ClientTests) TestRegions(c *C) { name := sessionName("goamz-region-test") perms := []ec2.IPPerm{{ Protocol: "tcp", FromPort: 80, ToPort: 80, SourceIPs: []string{"127.0.0.1/32"}, }} errs := make(chan error, len(allRegions)) for _, region := range allRegions { go func(r aws.Region) { e := ec2.New(s.ec2.Auth, r) _, err := e.AuthorizeSecurityGroup(ec2.SecurityGroup{Name: name}, perms) errs <- err }(region) } for _ = range allRegions { err := <-errs if err != nil { ec2_err, ok := err.(*ec2.Error) if ok { c.Check(ec2_err.Code, Matches, "InvalidGroup.NotFound") } else { c.Errorf("Non-EC2 error: %s", err) } } else { c.Errorf("Test should have errored but it seems to have succeeded") } } }
func (s *AmazonClientSuite) SetUpSuite(c *C) { if !testutil.Amazon { c.Skip("AmazonClientSuite tests not enabled") } s.srv.SetUp(c) s.ec2 = ec2.New(s.srv.auth, aws.USEast) }
func TestMonitorInvalidDesc(t *testing.T) { auth, err := aws.EnvAuth() if err != nil { panic(err) } s := ec2.New(auth, aws.EUWest) d, err := NewEC2InstanceDesc(s, "adfg", "asdf", "asd") if err != nil { t.Fatal(err) } m, err := d.StartChangeMonitor(time.Second * 1) if err != nil { t.Fatal(err) } quit := make(chan bool) go func() { for trace := range m.TraceChan { if trace.err == nil { t.Error("Monitor didn't fail on invalid arguments") } // only run once fmt.Println(trace.err.Error()) quit <- true } }() // wait for the error to return after a tick <-quit // exit the monitor m.Quit() }
func TestRealtimeTrace(t *testing.T) { auth, err := aws.EnvAuth() if err != nil { panic(err) } s := ec2.New(auth, aws.EUWest) m, err := NewEC2Monitor(s, "m1.medium", "Linux/UNIX", "eu-west-1b", nil) to := time.Now() from := to.AddDate(0, -3, 0) trace, err := m.Trace(from, to) if err != nil { t.Fatal(err) } if len(trace) == 0 { t.Fatal("trace did not produce any history") } if len(trace) < 5 { for i := 0; i < len(trace); i++ { pp := trace[i] fmt.Printf("\t%.4f - %v\n", pp.Price(), pp.Time()) } } else { fmt.Println("last 5 traces:") for i := 0; i < 5; i++ { pp := trace[i] fmt.Printf("\t%.4f - %v\n", pp.Price(), pp.Time()) } } pChan, errChan := m.Start(time.Second * 5) ticker := time.NewTicker(time.Minute * 5) fmt.Println("Starting EC2 Spot Price Monitor.\n\tTimeout: 5 minutes") for { select { case p := <-pChan: fmt.Printf("PriceChange: %v On: %v\n", p.Price(), p.Time()) case err := <-errChan: fmt.Println("error: ", err.Error()) return case <-ticker.C: fmt.Println("test shut down after 5 minutes") return } } fmt.Println("Stopping ticker, and exiting test..") ticker.Stop() fmt.Println("Done") }
// Make sure that no empty arguments are accepted. // TODO: make sure that the parameters // do not contains wild-cards '*' func TestEmptyDesc(t *testing.T) { auth, err := aws.EnvAuth() if err != nil { panic(err) } s := ec2.New(auth, aws.EUWest) _, err = NewEC2InstanceDesc(s, "", "", "") if err == nil { t.Fatal("Blank arguments accepted") } }
func (s *S) TestSignatureWithEndpointPath(c *C) { ec2.FakeTime(true) defer ec2.FakeTime(false) testServer.Response(200, nil, RebootInstancesExample) // https://bugs.launchpad.net/goamz/+bug/1022749 ec2 := ec2.New(s.ec2.Auth, aws.Region{EC2Endpoint: testServer.URL + "/services/Cloud"}) _, err := ec2.RebootInstances("i-10a64379") c.Assert(err, IsNil) req := testServer.WaitRequest() c.Assert(req.Form["Signature"], DeepEquals, []string{"gdG/vEm+c6ehhhfkrJy3+wuVzw/rzKR42TYelMwti7M="}) }
// Make sure that we fail gracefully // on invalid arguments func TestInvalidDesc(t *testing.T) { auth, err := aws.EnvAuth() if err != nil { panic(err) } s := ec2.New(auth, aws.EUWest) d, err := NewEC2InstanceDesc(s, "adfg", "asdf", "asd") if err != nil { t.Fatal(err) } _, err = d.GetHorizon(time.Now().AddDate(0, 0, -7)) if err == nil { t.Fatal("invalid parameters acepted") } }
func init() { runtime.GOMAXPROCS(4) auth, err := aws.EnvAuth() if err != nil { panic(err) } s := ec2.New(auth, aws.EUWest) desc, err = NewEC2InstanceDesc(s, "m1.medium", "Linux/UNIX", "eu-west-1b") if err != nil { panic(err) } }
func (s *S) SetUpSuite(c *C) { testServer.Start() auth := aws.Auth{"abc", "123"} s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: testServer.URL}) }