當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.Check方法代碼示例

本文整理匯總了Golang中github.com/motain/gocheck.C.Check方法的典型用法代碼示例。如果您正苦於以下問題:Golang C.Check方法的具體用法?Golang C.Check怎麽用?Golang C.Check使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/motain/gocheck.C的用法示例。


在下文中一共展示了C.Check方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestCases

func (s *V4SignerSuite) TestCases(c *gocheck.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))
		for _, v := range testCase.request.headers {
			h := strings.SplitN(v, ":", 2)
			req.Header.Add(h[0], h[1])
		}
		req.Header.Set("host", req.Host)

		t := signer.RequestTime(req)

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

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

		signature := signer.Signature(t, stringToSign)
		c.Check(signature, gocheck.Equals, testCase.signature, gocheck.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))

		signer.Sign(req)
		c.Check(req.Header.Get("Authorization"), gocheck.Equals, testCase.authorization, gocheck.Commentf("Testcase: %s", testCase.label))
	}
}
開發者ID:flyinprogrammer,項目名稱:ec2metaproxy,代碼行數:31,代碼來源:sign_test.go

示例2: TestConfigureHealthCheck

func (s *ClientTests) TestConfigureHealthCheck(c *gocheck.C) {
	createLBReq := elb.CreateLoadBalancer{
		Name:              "testlb",
		AvailabilityZones: []string{"us-east-1a"},
		Listeners: []elb.Listener{
			{
				InstancePort:     80,
				InstanceProtocol: "http",
				LoadBalancerPort: 80,
				Protocol:         "http",
			},
		},
	}
	_, err := s.elb.CreateLoadBalancer(&createLBReq)
	c.Assert(err, gocheck.IsNil)
	defer func() {
		_, err := s.elb.DeleteLoadBalancer(createLBReq.Name)
		c.Check(err, gocheck.IsNil)
	}()
	hc := elb.HealthCheck{
		HealthyThreshold:   10,
		Interval:           30,
		Target:             "HTTP:80/",
		Timeout:            5,
		UnhealthyThreshold: 2,
	}
	resp, err := s.elb.ConfigureHealthCheck(createLBReq.Name, &hc)
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.HealthCheck.HealthyThreshold, gocheck.Equals, 10)
	c.Assert(resp.HealthCheck.Interval, gocheck.Equals, 30)
	c.Assert(resp.HealthCheck.Target, gocheck.Equals, "HTTP:80/")
	c.Assert(resp.HealthCheck.Timeout, gocheck.Equals, 5)
	c.Assert(resp.HealthCheck.UnhealthyThreshold, gocheck.Equals, 2)
}
開發者ID:rsherman-kabam,項目名稱:go-amz,代碼行數:34,代碼來源:elbi_test.go

示例3: TestConfigureHealthCheckBadRequest

func (s *ClientTests) TestConfigureHealthCheckBadRequest(c *gocheck.C) {
	createLBReq := elb.CreateLoadBalancer{
		Name:              "testlb",
		AvailabilityZones: []string{"us-east-1a"},
		Listeners: []elb.Listener{
			{
				InstancePort:     80,
				InstanceProtocol: "http",
				LoadBalancerPort: 80,
				Protocol:         "http",
			},
		},
	}
	_, err := s.elb.CreateLoadBalancer(&createLBReq)
	c.Assert(err, gocheck.IsNil)
	defer func() {
		_, err := s.elb.DeleteLoadBalancer(createLBReq.Name)
		c.Check(err, gocheck.IsNil)
	}()
	hc := elb.HealthCheck{
		HealthyThreshold:   10,
		Interval:           30,
		Target:             "HTTP:80",
		Timeout:            5,
		UnhealthyThreshold: 2,
	}
	resp, err := s.elb.ConfigureHealthCheck(createLBReq.Name, &hc)
	c.Assert(resp, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
	expected := "HealthCheck HTTP Target must specify a port followed by a path that begins with a slash. e.g. HTTP:80/ping/this/path (ValidationError)"
	c.Assert(err.Error(), gocheck.Equals, expected)
}
開發者ID:rsherman-kabam,項目名稱:go-amz,代碼行數:32,代碼來源:elbi_test.go

示例4: TestRegions

// Communicate with all endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *gocheck.C) {
	errs := make(chan error, len(aws.Regions))
	for _, region := range aws.Regions {
		go func(r aws.Region) {
			s := s3.New(s.s3.Auth, r)
			b := s.Bucket("goamz-" + s.Auth.AccessKey)
			_, err := b.Get("non-existent")
			errs <- err
		}(region)
	}
	for _ = range aws.Regions {
		err := <-errs
		if err != nil {
			s3_err, ok := err.(*s3.Error)
			if ok {
				c.Check(s3_err.Code, gocheck.Matches, "NoSuchBucket")
			} else if _, ok = err.(*net.DNSError); ok {
				// Okay as well.
			} else {
				c.Errorf("Non-S3 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:27,代碼來源:s3i_test.go

示例5: TestRegions

// Communicate with all EC2 endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *gocheck.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.NewWithClient(s.ec2.Auth, r, testutil.DefaultClient)
			_, 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, gocheck.Matches, "InvalidGroup.NotFound")
			} else {
				c.Errorf("Non-EC2 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
開發者ID:rsherman-kabam,項目名稱:go-amz,代碼行數:31,代碼來源:ec2i_test.go

示例6: TestBasicFunctionality

func (s *ClientTests) TestBasicFunctionality(c *gocheck.C) {
	b := testBucket(s.s3)
	err := b.PutBucket(s3.PublicRead)
	c.Assert(err, gocheck.IsNil)

	err = b.Put("name", []byte("yo!"), "text/plain", s3.PublicRead, s3.Options{})
	c.Assert(err, gocheck.IsNil)
	defer b.Del("name")

	data, err := b.Get("name")
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(data), gocheck.Equals, "yo!")

	data, err = get(b.URL("name"))
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(data), gocheck.Equals, "yo!")

	buf := bytes.NewBufferString("hey!")
	err = b.PutReader("name2", buf, int64(buf.Len()), "text/plain", s3.Private, s3.Options{})
	c.Assert(err, gocheck.IsNil)
	defer b.Del("name2")

	rc, err := b.GetReader("name2")
	c.Assert(err, gocheck.IsNil)
	data, err = ioutil.ReadAll(rc)
	c.Check(err, gocheck.IsNil)
	c.Check(string(data), gocheck.Equals, "hey!")
	rc.Close()

	data, err = get(b.SignedURL("name2", time.Now().Add(time.Hour)))
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(data), gocheck.Equals, "hey!")

	if !s.authIsBroken {
		data, err = get(b.SignedURL("name2", time.Now().Add(-time.Hour)))
		c.Assert(err, gocheck.IsNil)
		c.Assert(string(data), gocheck.Matches, "(?s).*AccessDenied.*")
	}

	err = b.DelBucket()
	c.Assert(err, gocheck.NotNil)

	s3err, ok := err.(*s3.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(s3err.Code, gocheck.Equals, "BucketNotEmpty")
	c.Assert(s3err.BucketName, gocheck.Equals, b.Name)
	c.Assert(s3err.Message, gocheck.Equals, "The bucket you tried to delete is not empty")

	err = b.Del("name")
	c.Assert(err, gocheck.IsNil)
	err = b.Del("name2")
	c.Assert(err, gocheck.IsNil)

	err = b.DelBucket()
	c.Assert(err, gocheck.IsNil)
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:56,代碼來源:s3i_test.go

示例7: TestMarshalEmptySets

func (s *MarshallerSuite) TestMarshalEmptySets(c *gocheck.C) {
	testObj := testObjectWithEmptySets()
	attrs, err := dynamodb.MarshalAttributes(testObj)
	if err != nil {
		c.Errorf("Error from dynamodb.MarshalAttributes: %#v", err)
	}

	expected := testAttrsWithNilSets()
	c.Check(attrs, gocheck.DeepEquals, expected)
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:10,代碼來源:marshaller_test.go

示例8: terminateInstances

func terminateInstances(c *gocheck.C, e *ec2.EC2, insts []*ec2.Instance) {
	var ids []string
	for _, inst := range insts {
		if inst != nil {
			ids = append(ids, inst.InstanceId)
		}
	}
	_, err := e.TerminateInstances(ids)
	c.Check(err, gocheck.IsNil, gocheck.Commentf("%d INSTANCES LEFT RUNNING!!!", len(ids)))
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:10,代碼來源:ec2t_test.go

示例9: TestEmptyQuery

func (s *QueryBuilderSuite) TestEmptyQuery(c *gocheck.C) {
	q := dynamodb.NewEmptyQuery()
	queryString := q.String()
	expectedString := "{}"
	c.Check(queryString, gocheck.Equals, expectedString)

	if expectedString != queryString {
		c.Fatalf("Unexpected Query String : %s\n", queryString)
	}
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:10,代碼來源:query_builder_test.go

示例10: TestGetItemQuery

func (s *QueryBuilderSuite) TestGetItemQuery(c *gocheck.C) {
	primary := dynamodb.NewStringAttribute("domain", "")
	key := dynamodb.PrimaryKey{primary, nil}
	table := s.server.NewTable("sites", key)

	q := dynamodb.NewQuery(table)
	q.AddKey(table, &dynamodb.Key{HashKey: "test"})

	{
		queryJson, err := simplejson.NewJson([]byte(q.String()))
		if err != nil {
			c.Fatal(err)
		}

		expectedJson, err := simplejson.NewJson([]byte(`
		{
			"Key": {
				"domain": {
					"S": "test"
				}
			},
			"TableName": "sites"
		}
		`))
		if err != nil {
			c.Fatal(err)
		}
		c.Check(queryJson, gocheck.DeepEquals, expectedJson)
	}

	// Use ConsistentRead
	{
		q.ConsistentRead(true)
		queryJson, err := simplejson.NewJson([]byte(q.String()))
		if err != nil {
			c.Fatal(err)
		}

		expectedJson, err := simplejson.NewJson([]byte(`
		{
			"ConsistentRead": "true",
			"Key": {
				"domain": {
					"S": "test"
				}
			},
			"TableName": "sites"
		}
		`))
		if err != nil {
			c.Fatal(err)
		}
		c.Check(queryJson, gocheck.DeepEquals, expectedJson)
	}
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:55,代碼來源:query_builder_test.go

示例11: TestUpdateItemWithSet

func (s *ItemSuite) TestUpdateItemWithSet(c *gocheck.C) {
	attrs := []dynamodb.Attribute{
		*dynamodb.NewStringSetAttribute("list", []string{"A", "B"}),
	}

	var rk string
	if s.WithRange {
		rk = "1"
	}

	if ok, err := s.table.PutItem("NewHashKeyVal", rk, attrs); !ok {
		c.Error(err)
	}

	// UpdateItem with Add
	attrs = []dynamodb.Attribute{
		*dynamodb.NewStringSetAttribute("list", []string{"C"}),
	}
	pk := &dynamodb.Key{HashKey: "NewHashKeyVal", RangeKey: rk}
	if ok, err := s.table.AddAttributes(pk, attrs); !ok {
		c.Error(err)
	}

	// Get to verify Add operation
	if item, err := s.table.GetItem(pk); err != nil {
		c.Error(err)
	} else {
		if val, ok := item["list"]; ok {
			c.Check(val, gocheck.DeepEquals, dynamodb.NewStringSetAttribute("list", []string{"A", "B", "C"}))
		} else {
			c.Error("Expect count to be found")
		}
	}

	// UpdateItem with Delete
	attrs = []dynamodb.Attribute{
		*dynamodb.NewStringSetAttribute("list", []string{"A"}),
	}
	if ok, err := s.table.DeleteAttributes(pk, attrs); !ok {
		c.Error(err)
	}

	// Get to verify Delete operation
	if item, err := s.table.GetItem(pk); err != nil {
		c.Error(err)
	} else {
		if val, ok := item["list"]; ok {
			c.Check(val, gocheck.DeepEquals, dynamodb.NewStringSetAttribute("list", []string{"B", "C"}))
		} else {
			c.Error("Expect list to be remained")
		}
	}
}
開發者ID:rsherman-kabam,項目名稱:go-amz,代碼行數:53,代碼來源:item_test.go

示例12: TestDescribeLoadBalancers

func (s *ClientTests) TestDescribeLoadBalancers(c *gocheck.C) {
	createLBReq := elb.CreateLoadBalancer{
		Name:              "testlb",
		AvailabilityZones: []string{"us-east-1a"},
		Listeners: []elb.Listener{
			{
				InstancePort:     80,
				InstanceProtocol: "http",
				LoadBalancerPort: 80,
				Protocol:         "http",
			},
		},
	}
	_, err := s.elb.CreateLoadBalancer(&createLBReq)
	c.Assert(err, gocheck.IsNil)
	defer func() {
		_, err := s.elb.DeleteLoadBalancer(createLBReq.Name)
		c.Check(err, gocheck.IsNil)
	}()
	resp, err := s.elb.DescribeLoadBalancers()
	c.Assert(err, gocheck.IsNil)
	c.Assert(len(resp.LoadBalancerDescriptions) > 0, gocheck.Equals, true)
	c.Assert(resp.LoadBalancerDescriptions[0].AvailabilityZones, gocheck.DeepEquals, []string{"us-east-1a"})
	c.Assert(resp.LoadBalancerDescriptions[0].LoadBalancerName, gocheck.Equals, "testlb")
	c.Assert(resp.LoadBalancerDescriptions[0].Scheme, gocheck.Equals, "internet-facing")
	hc := elb.HealthCheck{
		HealthyThreshold:   10,
		Interval:           30,
		Target:             "TCP:80",
		Timeout:            5,
		UnhealthyThreshold: 2,
	}
	c.Assert(resp.LoadBalancerDescriptions[0].HealthCheck, gocheck.DeepEquals, hc)
	ld := []elb.ListenerDescription{
		{
			Listener: elb.Listener{
				Protocol:         "HTTP",
				LoadBalancerPort: 80,
				InstanceProtocol: "HTTP",
				InstancePort:     80,
			},
		},
	}
	c.Assert(resp.LoadBalancerDescriptions[0].ListenerDescriptions, gocheck.DeepEquals, ld)
	ssg := elb.SourceSecurityGroup{
		GroupName:  "amazon-elb-sg",
		OwnerAlias: "amazon-elb",
	}
	c.Assert(resp.LoadBalancerDescriptions[0].SourceSecurityGroup, gocheck.DeepEquals, ssg)
}
開發者ID:rsherman-kabam,項目名稱:go-amz,代碼行數:50,代碼來源:elbi_test.go

示例13: TestBucketList

func (s *ClientTests) TestBucketList(c *gocheck.C) {
	b := testBucket(s.s3)
	err := b.PutBucket(s3.Private)
	c.Assert(err, gocheck.IsNil)

	objData := make(map[string][]byte)
	for i, path := range objectNames {
		data := []byte(strings.Repeat("a", i))
		err := b.Put(path, data, "text/plain", s3.Private, s3.Options{})
		c.Assert(err, gocheck.IsNil)
		defer b.Del(path)
		objData[path] = data
	}

	for i, t := range listTests {
		c.Logf("test %d", i)
		resp, err := b.List(t.Prefix, t.Delimiter, t.Marker, t.MaxKeys)
		c.Assert(err, gocheck.IsNil)
		c.Check(resp.Name, gocheck.Equals, b.Name)
		c.Check(resp.Delimiter, gocheck.Equals, t.Delimiter)
		c.Check(resp.IsTruncated, gocheck.Equals, t.IsTruncated)
		c.Check(resp.CommonPrefixes, gocheck.DeepEquals, t.CommonPrefixes)
		checkContents(c, resp.Contents, objData, t.Contents)
	}
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:25,代碼來源:s3i_test.go

示例14: TestCreateRegisterAndDeregisterInstanceWithLoadBalancer

// Cost: 0.02 USD
func (s *ClientTests) TestCreateRegisterAndDeregisterInstanceWithLoadBalancer(c *gocheck.C) {
	createLBReq, instId := s.createInstanceAndLB(c)
	defer func() {
		_, err := s.elb.DeleteLoadBalancer(createLBReq.Name)
		c.Check(err, gocheck.IsNil)
		_, err = s.ec2.TerminateInstances([]string{instId})
		c.Check(err, gocheck.IsNil)
	}()
	resp, err := s.elb.RegisterInstancesWithLoadBalancer([]string{instId}, createLBReq.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.InstanceIds, gocheck.DeepEquals, []string{instId})
	resp2, err := s.elb.DeregisterInstancesFromLoadBalancer([]string{instId}, createLBReq.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp2, gocheck.Not(gocheck.Equals), "")
}
開發者ID:rsherman-kabam,項目名稱:go-amz,代碼行數:16,代碼來源:elbi_test.go

示例15: TestUnmarshalEmptySets

func (s *MarshallerSuite) TestUnmarshalEmptySets(c *gocheck.C) {
	testObj := &TestStruct{}

	attrMap := map[string]*dynamodb.Attribute{}
	attrs := testAttrsWithNilSets()
	for i, _ := range attrs {
		attrMap[attrs[i].Name] = &attrs[i]
	}

	err := dynamodb.UnmarshalAttributes(&attrMap, testObj)
	if err != nil {
		c.Fatalf("Error from dynamodb.UnmarshalAttributes: %#v (Built: %#v)", err, testObj)
	}

	expected := testObjectWithNilSets()
	c.Check(testObj, gocheck.DeepEquals, expected)
}
開發者ID:dutchcoders,項目名稱:goamz,代碼行數:17,代碼來源:marshaller_test.go


注:本文中的github.com/motain/gocheck.C.Check方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。