当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.New函数代码示例

本文整理汇总了Golang中github.com/stretchr/testify/assert.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMostSpecific

func TestMostSpecific(t *testing.T) {
	assert := assert.New(t)

	for _, t := range []struct {
		input    []string
		expected string
		err      error
	}{
		{
			[]string{"Organisation"},
			"Organisation",
			nil,
		}, {
			[]string{"Organisation", "PublicCompany", "Company"},
			"PublicCompany",
			nil,
		}, {
			[]string{"PublicCompany", "Organisation"},
			"PublicCompany",
			nil,
		}, {
			[]string{"Organisation", "PublicCompany", "PrivateCompany", "Company"},
			"",
			ErrNotHierarchy,
		}, {
			[]string{"zzzzzz", "yyyyyy"},
			"",
			ErrNotHierarchy,
		},
	} {
		ms, err := mostSpecific(t.input)
		assert.Equal(t.expected, ms)
		assert.Equal(t.err, err)
	}
}
开发者ID:Financial-Times,项目名称:neo-model-utils-go,代码行数:35,代码来源:uri_utils_test.go

示例2: TestCollect

func TestCollect(t *testing.T) {
	cm := &collectorManager{}

	firstTime := time.Now().Add(-time.Hour)
	secondTime := time.Now().Add(time.Hour)
	f1 := &fakeCollector{
		nextCollectionTime: firstTime,
	}
	f2 := &fakeCollector{
		nextCollectionTime: secondTime,
	}

	assert := assert.New(t)
	assert.NoError(cm.RegisterCollector(f1))
	assert.NoError(cm.RegisterCollector(f2))

	// First collection, everyone gets collected from.
	nextTime, _, err := cm.Collect()
	assert.Equal(firstTime, nextTime)
	assert.NoError(err)
	assert.Equal(1, f1.collectedFrom)
	assert.Equal(1, f2.collectedFrom)

	f1.nextCollectionTime = time.Now().Add(2 * time.Hour)

	// Second collection, only the one that is ready gets collected from.
	nextTime, _, err = cm.Collect()
	assert.Equal(secondTime, nextTime)
	assert.NoError(err)
	assert.Equal(2, f1.collectedFrom)
	assert.Equal(1, f2.collectedFrom)
}
开发者ID:zenlinTechnofreak,项目名称:cadvisor,代码行数:32,代码来源:collector_manager_test.go

示例3: Test_Implements_Session

func Test_Implements_Session(t *testing.T) {
	t.Parallel()
	a := assert.New(t)
	s := &facebook.Session{}

	a.Implements((*goth.Session)(nil), s)
}
开发者ID:rossnanop,项目名称:goth,代码行数:7,代码来源:session_test.go

示例4: TestBlobLen

func TestBlobLen(t *testing.T) {
	assert := assert.New(t)
	b := NewBlob(&bytes.Buffer{})
	assert.Equal(uint64(0), b.Len())
	b = NewBlob(bytes.NewBuffer([]byte{0x01}))
	assert.Equal(uint64(1), b.Len())
}
开发者ID:arv,项目名称:noms-old,代码行数:7,代码来源:blob_test.go

示例5: TestGetNodeAddresses

// TestGetNodeAddresses verifies that proper results are returned
// when requesting node addresses.
func TestGetNodeAddresses(t *testing.T) {
	assert := assert.New(t)

	fakeNodeClient := fake.NewSimpleClientset(registrytest.MakeNodeList([]string{"node1", "node2"}, api.NodeResources{})).Core().Nodes()
	addressProvider := nodeAddressProvider{fakeNodeClient}

	// Fail case (no addresses associated with nodes)
	nodes, _ := fakeNodeClient.List(api.ListOptions{})
	addrs, err := addressProvider.externalAddresses()

	assert.Error(err, "addresses should have caused an error as there are no addresses.")
	assert.Equal([]string(nil), addrs)

	// Pass case with External type IP
	nodes, _ = fakeNodeClient.List(api.ListOptions{})
	for index := range nodes.Items {
		nodes.Items[index].Status.Addresses = []api.NodeAddress{{Type: api.NodeExternalIP, Address: "127.0.0.1"}}
		fakeNodeClient.Update(&nodes.Items[index])
	}
	addrs, err = addressProvider.externalAddresses()
	assert.NoError(err, "addresses should not have returned an error.")
	assert.Equal([]string{"127.0.0.1", "127.0.0.1"}, addrs)

	// Pass case with LegacyHost type IP
	nodes, _ = fakeNodeClient.List(api.ListOptions{})
	for index := range nodes.Items {
		nodes.Items[index].Status.Addresses = []api.NodeAddress{{Type: api.NodeLegacyHostIP, Address: "127.0.0.2"}}
		fakeNodeClient.Update(&nodes.Items[index])
	}
	addrs, err = addressProvider.externalAddresses()
	assert.NoError(err, "addresses failback should not have returned an error.")
	assert.Equal([]string{"127.0.0.2", "127.0.0.2"}, addrs)
}
开发者ID:oszi,项目名称:kubernetes,代码行数:35,代码来源:master_test.go

示例6: Test_MaxMessageIdError

func Test_MaxMessageIdError(t *testing.T) {
	a := assert.New(t)
	store := New("/TestDir")

	_, err := store.MaxMessageID("p2")
	a.NotNil(err)
}
开发者ID:smancke,项目名称:guble,代码行数:7,代码来源:message_store_test.go

示例7: Test_DoInTxError

func Test_DoInTxError(t *testing.T) {
	a := assert.New(t)
	mStore := New("/TestDir")

	err := mStore.DoInTx("p2", nil)
	a.NotNil(err)
}
开发者ID:smancke,项目名称:guble,代码行数:7,代码来源:message_store_test.go

示例8: TestFSMHandlerEstablish_HoldTimerExpired

func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) {
	assert := assert.New(t)
	m := NewMockConnection()

	p, h := makePeerAndHandler()

	// push mock connection
	p.fsm.conn = m

	// set keepalive ticker
	p.fsm.pConf.Timers.State.NegotiatedHoldTime = 3

	msg := keepalive()
	header, _ := msg.Header.Serialize()
	body, _ := msg.Body.Serialize()

	pushPackets := func() {
		// first keepalive from peer
		m.setData(header)
		m.setData(body)
	}

	// set holdtime
	p.fsm.pConf.Timers.Config.HoldTime = 2
	p.fsm.pConf.Timers.State.NegotiatedHoldTime = 2

	go pushPackets()
	state, _ := h.established()
	time.Sleep(time.Second * 1)
	assert.Equal(bgp.BGP_FSM_IDLE, state)
	lastMsg := m.sendBuf[len(m.sendBuf)-1]
	sent, _ := bgp.ParseBGPMessage(lastMsg)
	assert.Equal(uint8(bgp.BGP_MSG_NOTIFICATION), sent.Header.Type)
	assert.Equal(uint8(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED), sent.Body.(*bgp.BGPNotification).ErrorCode)
}
开发者ID:abhinandanpb,项目名称:gobgp,代码行数:35,代码来源:fsm_test.go

示例9: TestPoliciesList

func TestPoliciesList(t *testing.T) {
	var httpStatusCode int
	var err error
	var reslut []apilib.RepPolicy

	assert := assert.New(t)
	apiTest := newHarborAPI()

	fmt.Println("Testing Policies Get/List API")

	//-------------------case 1 : response code = 200------------------------//
	fmt.Println("case 1 : response code = 200")
	projectID := "1"
	httpStatusCode, reslut, err = apiTest.ListPolicies(*admin, addPolicyName, projectID)
	if err != nil {
		t.Error("Error while get policies", err.Error())
		t.Log(err)
	} else {
		assert.Equal(int(200), httpStatusCode, "httpStatusCode should be 200")
		addPolicyID = int(reslut[0].Id)
	}

	//-------------------case 2 : response code = 400------------------------//
	fmt.Println("case 2 : response code = 400:invalid projectID")
	projectID = "cc"
	httpStatusCode, reslut, err = apiTest.ListPolicies(*admin, addPolicyName, projectID)
	if err != nil {
		t.Error("Error while get policies", err.Error())
		t.Log(err)
	} else {
		assert.Equal(int(400), httpStatusCode, "httpStatusCode should be 400")
	}

}
开发者ID:vmware,项目名称:harbor,代码行数:34,代码来源:replication_policy_test.go

示例10: TestDateParseLayout

func TestDateParseLayout(t *testing.T) {
	assert := assert.New(t)
	testCases := []struct {
		Text     string
		Layout   string
		Expected Date
		Error    bool
	}{
		{
			Text:     "11 Jan 1994",
			Layout:   "02 Jan 2006",
			Expected: DateFor(1994, 1, 11),
		},
		{
			Text:   "Jan 11 1994",
			Layout: "02 Jan 2006",
			Error:  true,
		},
	}

	for _, tc := range testCases {
		d, err := DateParseLayout(tc.Layout, tc.Text)
		if tc.Error {
			assert.Error(err)
		} else {
			assert.NoError(err)
			assert.Equal(tc.Expected, d, datesNotEqual(tc.Expected, d))
		}
	}
}
开发者ID:spkg,项目名称:local,代码行数:30,代码来源:date_test.go

示例11: TestReadAll

func TestReadAll(t *testing.T) {
	assert := assert.New(t)
	m := NewMockConnection()
	msg := open()
	expected1, _ := msg.Header.Serialize()
	expected2, _ := msg.Body.Serialize()

	pushBytes := func() {
		fmt.Println("push 5 bytes")
		m.setData(expected1[0:5])
		fmt.Println("push rest")
		m.setData(expected1[5:])
		fmt.Println("push bytes at once")
		m.setData(expected2)
	}

	go pushBytes()

	var actual1 []byte
	actual1, _ = readAll(m, bgp.BGP_HEADER_LENGTH)
	fmt.Println(actual1)
	assert.Equal(expected1, actual1)

	var actual2 []byte
	actual2, _ = readAll(m, len(expected2))
	fmt.Println(actual2)
	assert.Equal(expected2, actual2)
}
开发者ID:abhinandanpb,项目名称:gobgp,代码行数:28,代码来源:fsm_test.go

示例12: TestDateSub

func TestDateSub(t *testing.T) {
	assert := assert.New(t)
	testCases := []struct {
		Date1 Date
		Date2 Date
		Days  int
	}{
		{
			Date1: DateFor(1994, 11, 14),
			Date2: DateFor(1994, 11, 13),
			Days:  1,
		},
		{
			Date1: DateFor(1994, 11, 14),
			Date2: DateFor(1994, 11, 15),
			Days:  -1,
		},
		{
			Date1: DateFor(1994, 11, 14),
			Date2: DateFor(1992, 12, 16),
			Days:  698,
		},
	}
	for _, tc := range testCases {
		d := tc.Date1.Sub(tc.Date2)
		assert.Equal(time.Duration(tc.Days)*time.Hour*24, d)
	}
}
开发者ID:spkg,项目名称:local,代码行数:28,代码来源:date_test.go

示例13: TestDateUnmarshalBinaryError

// Test for case where attempt made to unmarshal invalid binary data
func TestDateUnmarshalBinaryError(t *testing.T) {
	assert := assert.New(t)
	data := []byte("xxxx")
	var d Date
	err := d.UnmarshalBinary(data)
	assert.Error(err)
}
开发者ID:spkg,项目名称:local,代码行数:8,代码来源:date_test.go

示例14: TestPlugin_New

// Test to create the scheduler plugin with an empty plugin config
func TestPlugin_New(t *testing.T) {
	assert := assert.New(t)

	c := PluginConfig{}
	p := NewPlugin(&c)
	assert.NotNil(p)
}
开发者ID:MikaelCluseau,项目名称:kubernetes,代码行数:8,代码来源:plugin_test.go

示例15: TestGenerateSSHKey

// TestGenerateSSHKey verifies that SSH key generation does indeed
// generate keys even with keys already exist.
func TestGenerateSSHKey(t *testing.T) {
	assert := assert.New(t)

	privateKey := generateTempFilePath("private")
	publicKey := generateTempFilePath("public")

	// Make sure we have no test keys laying around
	os.Remove(privateKey)
	os.Remove(publicKey)

	// Pass case: Sunny day case
	err := generateSSHKey(privateKey, publicKey)
	assert.NoError(err, "generateSSHKey should not have retuend an error: %s", err)

	// Pass case: PrivateKey exists test case
	os.Remove(publicKey)
	err = generateSSHKey(privateKey, publicKey)
	assert.NoError(err, "generateSSHKey should not have retuend an error: %s", err)

	// Pass case: PublicKey exists test case
	os.Remove(privateKey)
	err = generateSSHKey(privateKey, publicKey)
	assert.NoError(err, "generateSSHKey should not have retuend an error: %s", err)

	// Make sure we have no test keys laying around
	os.Remove(privateKey)
	os.Remove(publicKey)

	// TODO: testing error cases where the file can not be removed?
}
开发者ID:ttysteale,项目名称:kubernetes-api,代码行数:32,代码来源:tunneler_test.go


注:本文中的github.com/stretchr/testify/assert.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。