Skip to content

Commit

Permalink
Migrate from gocheck to check
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeken committed Apr 18, 2014
1 parent 3a91703 commit 3bee057
Show file tree
Hide file tree
Showing 35 changed files with 2,171 additions and 2,171 deletions.
38 changes: 19 additions & 19 deletions aws/attempt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package aws_test

import (
"github.com/crowdmob/goamz/aws"
"launchpad.net/gocheck"
"gopkg.in/check.v1"
"time"
)

func (S) TestAttemptTiming(c *gocheck.C) {
func (S) TestAttemptTiming(c *check.C) {
testAttempt := aws.AttemptStrategy{
Total: 0.25e9,
Delay: 0.1e9,
Expand All @@ -18,7 +18,7 @@ func (S) TestAttemptTiming(c *gocheck.C) {
got = append(got, time.Now().Sub(t0))
}
got = append(got, time.Now().Sub(t0))
c.Assert(got, gocheck.HasLen, len(want))
c.Assert(got, check.HasLen, len(want))
const margin = 0.01e9
for i, got := range want {
lo := want[i] - margin
Expand All @@ -29,29 +29,29 @@ func (S) TestAttemptTiming(c *gocheck.C) {
}
}

func (S) TestAttemptNextHasNext(c *gocheck.C) {
func (S) TestAttemptNextHasNext(c *check.C) {
a := aws.AttemptStrategy{}.Start()
c.Assert(a.Next(), gocheck.Equals, true)
c.Assert(a.Next(), gocheck.Equals, false)
c.Assert(a.Next(), check.Equals, true)
c.Assert(a.Next(), check.Equals, false)

a = aws.AttemptStrategy{}.Start()
c.Assert(a.Next(), gocheck.Equals, true)
c.Assert(a.HasNext(), gocheck.Equals, false)
c.Assert(a.Next(), gocheck.Equals, false)
c.Assert(a.Next(), check.Equals, true)
c.Assert(a.HasNext(), check.Equals, false)
c.Assert(a.Next(), check.Equals, false)

a = aws.AttemptStrategy{Total: 2e8}.Start()
c.Assert(a.Next(), gocheck.Equals, true)
c.Assert(a.HasNext(), gocheck.Equals, true)
c.Assert(a.Next(), check.Equals, true)
c.Assert(a.HasNext(), check.Equals, true)
time.Sleep(2e8)
c.Assert(a.HasNext(), gocheck.Equals, true)
c.Assert(a.Next(), gocheck.Equals, true)
c.Assert(a.Next(), gocheck.Equals, false)
c.Assert(a.HasNext(), check.Equals, true)
c.Assert(a.Next(), check.Equals, true)
c.Assert(a.Next(), check.Equals, false)

a = aws.AttemptStrategy{Total: 1e8, Min: 2}.Start()
time.Sleep(1e8)
c.Assert(a.Next(), gocheck.Equals, true)
c.Assert(a.HasNext(), gocheck.Equals, true)
c.Assert(a.Next(), gocheck.Equals, true)
c.Assert(a.HasNext(), gocheck.Equals, false)
c.Assert(a.Next(), gocheck.Equals, false)
c.Assert(a.Next(), check.Equals, true)
c.Assert(a.HasNext(), check.Equals, true)
c.Assert(a.Next(), check.Equals, true)
c.Assert(a.HasNext(), check.Equals, false)
c.Assert(a.Next(), check.Equals, false)
}
58 changes: 29 additions & 29 deletions aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,92 @@ package aws_test

import (
"github.com/crowdmob/goamz/aws"
"launchpad.net/gocheck"
"gopkg.in/check.v1"
"os"
"strings"
"testing"
"time"
)

func Test(t *testing.T) {
gocheck.TestingT(t)
check.TestingT(t)
}

var _ = gocheck.Suite(&S{})
var _ = check.Suite(&S{})

type S struct {
environ []string
}

func (s *S) SetUpSuite(c *gocheck.C) {
func (s *S) SetUpSuite(c *check.C) {
s.environ = os.Environ()
}

func (s *S) TearDownTest(c *gocheck.C) {
func (s *S) TearDownTest(c *check.C) {
os.Clearenv()
for _, kv := range s.environ {
l := strings.SplitN(kv, "=", 2)
os.Setenv(l[0], l[1])
}
}

func (s *S) TestEnvAuthNoSecret(c *gocheck.C) {
func (s *S) TestEnvAuthNoSecret(c *check.C) {
os.Clearenv()
_, err := aws.EnvAuth()
c.Assert(err, gocheck.ErrorMatches, "AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment")
c.Assert(err, check.ErrorMatches, "AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment")
}

func (s *S) TestEnvAuthNoAccess(c *gocheck.C) {
func (s *S) TestEnvAuthNoAccess(c *check.C) {
os.Clearenv()
os.Setenv("AWS_SECRET_ACCESS_KEY", "foo")
_, err := aws.EnvAuth()
c.Assert(err, gocheck.ErrorMatches, "AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment")
c.Assert(err, check.ErrorMatches, "AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment")
}

func (s *S) TestEnvAuth(c *gocheck.C) {
func (s *S) TestEnvAuth(c *check.C) {
os.Clearenv()
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
os.Setenv("AWS_ACCESS_KEY_ID", "access")
auth, err := aws.EnvAuth()
c.Assert(err, gocheck.IsNil)
c.Assert(auth, gocheck.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
c.Assert(err, check.IsNil)
c.Assert(auth, check.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}

func (s *S) TestEnvAuthAlt(c *gocheck.C) {
func (s *S) TestEnvAuthAlt(c *check.C) {
os.Clearenv()
os.Setenv("AWS_SECRET_KEY", "secret")
os.Setenv("AWS_ACCESS_KEY", "access")
auth, err := aws.EnvAuth()
c.Assert(err, gocheck.IsNil)
c.Assert(auth, gocheck.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
c.Assert(err, check.IsNil)
c.Assert(auth, check.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}

func (s *S) TestGetAuthStatic(c *gocheck.C) {
func (s *S) TestGetAuthStatic(c *check.C) {
exptdate := time.Now().Add(time.Hour)
auth, err := aws.GetAuth("access", "secret", "token", exptdate)
c.Assert(err, gocheck.IsNil)
c.Assert(auth.AccessKey, gocheck.Equals, "access")
c.Assert(auth.SecretKey, gocheck.Equals, "secret")
c.Assert(auth.Token(), gocheck.Equals, "token")
c.Assert(auth.Expiration(), gocheck.Equals, exptdate)
c.Assert(err, check.IsNil)
c.Assert(auth.AccessKey, check.Equals, "access")
c.Assert(auth.SecretKey, check.Equals, "secret")
c.Assert(auth.Token(), check.Equals, "token")
c.Assert(auth.Expiration(), check.Equals, exptdate)
}

func (s *S) TestGetAuthEnv(c *gocheck.C) {
func (s *S) TestGetAuthEnv(c *check.C) {
os.Clearenv()
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
os.Setenv("AWS_ACCESS_KEY_ID", "access")
auth, err := aws.GetAuth("", "", "", time.Time{})
c.Assert(err, gocheck.IsNil)
c.Assert(auth, gocheck.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
c.Assert(err, check.IsNil)
c.Assert(auth, check.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}

func (s *S) TestEncode(c *gocheck.C) {
c.Assert(aws.Encode("foo"), gocheck.Equals, "foo")
c.Assert(aws.Encode("/"), gocheck.Equals, "%2F")
func (s *S) TestEncode(c *check.C) {
c.Assert(aws.Encode("foo"), check.Equals, "foo")
c.Assert(aws.Encode("/"), check.Equals, "%2F")
}

func (s *S) TestRegionsAreNamed(c *gocheck.C) {
func (s *S) TestRegionsAreNamed(c *check.C) {
for n, r := range aws.Regions {
c.Assert(n, gocheck.Equals, r.Name)
c.Assert(n, check.Equals, r.Name)
}
}
20 changes: 10 additions & 10 deletions aws/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package aws_test
import (
"fmt"
"github.com/crowdmob/goamz/aws"
"launchpad.net/gocheck"
"gopkg.in/check.v1"
"net/http"
"strings"
"time"
)

var _ = gocheck.Suite(&V4SignerSuite{})
var _ = check.Suite(&V4SignerSuite{})

type V4SignerSuite struct {
auth aws.Auth
Expand All @@ -34,7 +34,7 @@ type V4SignerSuiteCaseRequest struct {
body string
}

func (s *V4SignerSuite) SetUpSuite(c *gocheck.C) {
func (s *V4SignerSuite) SetUpSuite(c *check.C) {
s.auth = aws.Auth{AccessKey: "AKIDEXAMPLE", SecretKey: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
s.region = aws.USEast

Expand Down Expand Up @@ -465,13 +465,13 @@ func (s *V4SignerSuite) SetUpSuite(c *gocheck.C) {
)
}

func (s *V4SignerSuite) TestCases(c *gocheck.C) {
func (s *V4SignerSuite) TestCases(c *check.C) {
signer := aws.NewV4Signer(s.auth, "host", s.region)

for _, testCase := range s.cases {

req, err := http.NewRequest(testCase.request.method, "http://"+testCase.request.host+testCase.request.url, strings.NewReader(testCase.request.body))
c.Assert(err, gocheck.IsNil, gocheck.Commentf("Testcase: %s", testCase.label))
c.Assert(err, check.IsNil, check.Commentf("Testcase: %s", testCase.label))
for _, v := range testCase.request.headers {
h := strings.SplitN(v, ":", 2)
req.Header.Add(h[0], h[1])
Expand All @@ -481,19 +481,19 @@ func (s *V4SignerSuite) TestCases(c *gocheck.C) {
t := signer.RequestTime(req)

canonicalRequest := signer.CanonicalRequest(req)
c.Check(canonicalRequest, gocheck.Equals, testCase.canonicalRequest, gocheck.Commentf("Testcase: %s", testCase.label))
c.Check(canonicalRequest, check.Equals, testCase.canonicalRequest, check.Commentf("Testcase: %s", testCase.label))

stringToSign := signer.StringToSign(t, canonicalRequest)
c.Check(stringToSign, gocheck.Equals, testCase.stringToSign, gocheck.Commentf("Testcase: %s", testCase.label))
c.Check(stringToSign, check.Equals, testCase.stringToSign, check.Commentf("Testcase: %s", testCase.label))

signature := signer.Signature(t, stringToSign)
c.Check(signature, gocheck.Equals, testCase.signature, gocheck.Commentf("Testcase: %s", testCase.label))
c.Check(signature, check.Equals, testCase.signature, check.Commentf("Testcase: %s", testCase.label))

authorization := signer.Authorization(req.Header, t, signature)
c.Check(authorization, gocheck.Equals, testCase.authorization, gocheck.Commentf("Testcase: %s", testCase.label))
c.Check(authorization, check.Equals, testCase.authorization, check.Commentf("Testcase: %s", testCase.label))

signer.Sign(req)
c.Check(req.Header.Get("Authorization"), gocheck.Equals, testCase.authorization, gocheck.Commentf("Testcase: %s", testCase.label))
c.Check(req.Header.Get("Authorization"), check.Equals, testCase.authorization, check.Commentf("Testcase: %s", testCase.label))
}
}

Expand Down
68 changes: 34 additions & 34 deletions cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import (
"github.com/crowdmob/goamz/aws"
"github.com/crowdmob/goamz/cloudwatch"
"github.com/crowdmob/goamz/testutil"
"launchpad.net/gocheck"
"gopkg.in/check.v1"
"testing"
)

func Test(t *testing.T) {
gocheck.TestingT(t)
check.TestingT(t)
}

type S struct {
cw *cloudwatch.CloudWatch
}

var _ = gocheck.Suite(&S{})
var _ = check.Suite(&S{})

var testServer = testutil.NewHTTPServer()

func (s *S) SetUpSuite(c *gocheck.C) {
func (s *S) SetUpSuite(c *check.C) {
testServer.Start()
auth := aws.Auth{AccessKey: "abc", SecretKey: "123"}
s.cw, _ = cloudwatch.NewCloudWatch(auth, aws.ServiceInfo{testServer.URL, aws.V2Signature})
}

func (s *S) TearDownTest(c *gocheck.C) {
func (s *S) TearDownTest(c *check.C) {
testServer.Flush()
}

Expand All @@ -45,27 +45,27 @@ func getTestAlarm() *cloudwatch.MetricAlarm {
return alarm
}

func (s *S) TestPutAlarm(c *gocheck.C) {
func (s *S) TestPutAlarm(c *check.C) {
testServer.Response(200, nil, "<RequestId>123</RequestId>")

alarm := getTestAlarm()

_, err := s.cw.PutMetricAlarm(alarm)
c.Assert(err, gocheck.IsNil)
c.Assert(err, check.IsNil)

req := testServer.WaitRequest()
c.Assert(req.Method, gocheck.Equals, "POST")
c.Assert(req.URL.Path, gocheck.Equals, "/")
c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"PutMetricAlarm"})
c.Assert(req.Form["AlarmName"], gocheck.DeepEquals, []string{"TestAlarm"})
c.Assert(req.Form["ComparisonOperator"], gocheck.DeepEquals, []string{"LessThanThreshold"})
c.Assert(req.Form["EvaluationPeriods"], gocheck.DeepEquals, []string{"5"})
c.Assert(req.Form["Threshold"], gocheck.DeepEquals, []string{"1.0000000000E+00"})
c.Assert(req.Form["Period"], gocheck.DeepEquals, []string{"60"})
c.Assert(req.Form["Statistic"], gocheck.DeepEquals, []string{"Sum"})
c.Assert(req.Method, check.Equals, "POST")
c.Assert(req.URL.Path, check.Equals, "/")
c.Assert(req.Form["Action"], check.DeepEquals, []string{"PutMetricAlarm"})
c.Assert(req.Form["AlarmName"], check.DeepEquals, []string{"TestAlarm"})
c.Assert(req.Form["ComparisonOperator"], check.DeepEquals, []string{"LessThanThreshold"})
c.Assert(req.Form["EvaluationPeriods"], check.DeepEquals, []string{"5"})
c.Assert(req.Form["Threshold"], check.DeepEquals, []string{"1.0000000000E+00"})
c.Assert(req.Form["Period"], check.DeepEquals, []string{"60"})
c.Assert(req.Form["Statistic"], check.DeepEquals, []string{"Sum"})
}

func (s *S) TestPutAlarmWithAction(c *gocheck.C) {
func (s *S) TestPutAlarmWithAction(c *check.C) {
testServer.Response(200, nil, "<RequestId>123</RequestId>")

alarm := getTestAlarm()
Expand All @@ -78,41 +78,41 @@ func (s *S) TestPutAlarmWithAction(c *gocheck.C) {
alarm.AlarmActions = actions

_, err := s.cw.PutMetricAlarm(alarm)
c.Assert(err, gocheck.IsNil)
c.Assert(err, check.IsNil)

req := testServer.WaitRequest()
c.Assert(req.Method, gocheck.Equals, "POST")
c.Assert(req.URL.Path, gocheck.Equals, "/")
c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"PutMetricAlarm"})
c.Assert(req.Form["AlarmActions.member.1"], gocheck.DeepEquals, []string{"123"})
c.Assert(req.Form["AlarmName"], gocheck.DeepEquals, []string{"TestAlarm"})
c.Assert(req.Form["ComparisonOperator"], gocheck.DeepEquals, []string{"LessThanThreshold"})
c.Assert(req.Form["EvaluationPeriods"], gocheck.DeepEquals, []string{"5"})
c.Assert(req.Form["Threshold"], gocheck.DeepEquals, []string{"1.0000000000E+00"})
c.Assert(req.Form["Period"], gocheck.DeepEquals, []string{"60"})
c.Assert(req.Form["Statistic"], gocheck.DeepEquals, []string{"Sum"})
c.Assert(req.Method, check.Equals, "POST")
c.Assert(req.URL.Path, check.Equals, "/")
c.Assert(req.Form["Action"], check.DeepEquals, []string{"PutMetricAlarm"})
c.Assert(req.Form["AlarmActions.member.1"], check.DeepEquals, []string{"123"})
c.Assert(req.Form["AlarmName"], check.DeepEquals, []string{"TestAlarm"})
c.Assert(req.Form["ComparisonOperator"], check.DeepEquals, []string{"LessThanThreshold"})
c.Assert(req.Form["EvaluationPeriods"], check.DeepEquals, []string{"5"})
c.Assert(req.Form["Threshold"], check.DeepEquals, []string{"1.0000000000E+00"})
c.Assert(req.Form["Period"], check.DeepEquals, []string{"60"})
c.Assert(req.Form["Statistic"], check.DeepEquals, []string{"Sum"})
}

func (s *S) TestPutAlarmInvalidComapirsonOperator(c *gocheck.C) {
func (s *S) TestPutAlarmInvalidComapirsonOperator(c *check.C) {
testServer.Response(200, nil, "<RequestId>123</RequestId>")

alarm := getTestAlarm()

alarm.ComparisonOperator = "LessThan"

_, err := s.cw.PutMetricAlarm(alarm)
c.Assert(err, gocheck.NotNil)
c.Assert(err.Error(), gocheck.Equals, "ComparisonOperator is not valid")
c.Assert(err, check.NotNil)
c.Assert(err.Error(), check.Equals, "ComparisonOperator is not valid")
}

func (s *S) TestPutAlarmInvalidStatistic(c *gocheck.C) {
func (s *S) TestPutAlarmInvalidStatistic(c *check.C) {
testServer.Response(200, nil, "<RequestId>123</RequestId>")

alarm := getTestAlarm()

alarm.Statistic = "Count"

_, err := s.cw.PutMetricAlarm(alarm)
c.Assert(err, gocheck.NotNil)
c.Assert(err.Error(), gocheck.Equals, "Invalid statistic value supplied")
c.Assert(err, check.NotNil)
c.Assert(err.Error(), check.Equals, "Invalid statistic value supplied")
}
Loading

0 comments on commit 3bee057

Please sign in to comment.