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


Golang require.Panics函数代码示例

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


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

示例1: TestPanics

func TestPanics(t *testing.T) {

	require.Panics(t, func() {
		New().Add(0, 0)
	}, "Zeros")
	require.Panics(t, func() {
		New().Add(0, 1)
	}, "Zero duration")
	require.Panics(t, func() {
		New().Add(1, 0)
	}, "Zero sleep")
	require.Panics(t, func() {
		New().Add(1, 2)
	}, "sleep > duration")
	require.Panics(t, func() {
		New().Add(10, 8)
	}, "duration % sleep")

}
开发者ID:jmptrader,项目名称:pat,代码行数:19,代码来源:sleep_int_test.go

示例2: TestExclusiveLock

func TestExclusiveLock(t *testing.T) {
	el := makeExclusiveLock()
	el.lock()
	defer el.unlock()

	// This must leave el unlocked.
	require.Panics(t, func() {
		el.lock()
	})
}
开发者ID:keybase,项目名称:kbfs-beta,代码行数:10,代码来源:leveled_mutex_test.go

示例3: TestLeveledMutexIncorrect

func TestLeveledMutexIncorrect(t *testing.T) {
	mu1 := makeLeveledMutex(mutexLevel(testFirst), &sync.Mutex{})
	mu2 := makeLeveledMutex(mutexLevel(testSecond), &sync.Mutex{})
	mu3 := makeLeveledMutex(mutexLevel(testThird), &sync.Mutex{})

	state := makeLevelState(testMutexLevelToString)

	require.Panics(t, func() {
		mu1.AssertLocked(state)
	})

	mu2.Lock(state)

	require.Panics(t, func() {
		mu2.AssertUnlocked(state)
	})

	defer func() {
		mu2.Unlock(state)

		require.Panics(t, func() {
			mu2.AssertLocked(state)
		})
	}()

	// This must leave mu1 unlocked.
	require.Panics(t, func() {
		mu1.Lock(state)
	})

	mu3.Lock(state)
	defer mu3.Unlock(state)

	// This must leave mu2 locked.
	require.Panics(t, func() {
		mu2.Unlock(state)
	})
}
开发者ID:keybase,项目名称:kbfs-beta,代码行数:38,代码来源:leveled_mutex_test.go

示例4: TestOwner

func TestOwner(t *testing.T) {
	ring1 := New(start, end, peer1name)
	require.True(t, ring1.Contains(start), "start should be in ring")
	require.False(t, ring1.Contains(end), "end should not be in ring")

	require.Equal(t, router.UnknownPeerName, ring1.Owner(start))

	ring1.ClaimItAll()
	ring1.GrantRangeToHost(middle, end, peer2name)
	require.Equal(t, peer1name, ring1.Owner(start))
	require.Equal(t, peer2name, ring1.Owner(middle))
	require.Panics(t, func() {
		ring1.Owner(end)
	})

}
开发者ID:rahulxkrishna,项目名称:weave,代码行数:16,代码来源:ring_test.go

示例5: TestEndToEnd

func TestEndToEnd(t *testing.T) {
	tMock := testingTMock{t, 0}

	dir, err := ioutil.TempDir("", "yarpcgorecorder")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(dir) // clean up

	// First we double check that our cache is empty.
	recorder := NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir))

	withDisconnectedClient(t, recorder, func(client raw.Client) {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
		defer cancel()

		require.Panics(t, func() {
			client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
		})
		assert.Equal(t, tMock.fatalCount, 1)
	})

	// Now let's record our call.
	recorder = NewRecorder(&tMock, RecordMode(Overwrite), RecordsPath(dir))

	withConnectedClient(t, recorder, func(client raw.Client) {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
		defer cancel()

		rbody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
		require.NoError(t, err)
		assert.Equal(t, rbody, []byte("Hello, World"))
	})

	// Now replay the call.
	recorder = NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir))

	withDisconnectedClient(t, recorder, func(client raw.Client) {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
		defer cancel()

		rbody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
		require.NoError(t, err)
		assert.Equal(t, rbody, []byte("Hello, World"))
	})
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:46,代码来源:recorder_test.go

示例6: TestInsert

func TestInsert(t *testing.T) {
	ring := New(start, end, peer1name)
	ring.Entries = []*entry{{Token: start, Peer: peer1name, Free: 255}}

	require.Panics(t, func() {
		ring.Entries.insert(entry{Token: start, Peer: peer1name})
	})

	ring.Entries.entry(0).Free = 0
	ring.Entries.insert(entry{Token: dot245, Peer: peer1name})
	ring2 := New(start, end, peer1name)
	ring2.Entries = []*entry{{Token: start, Peer: peer1name, Free: 0}, {Token: dot245, Peer: peer1name}}
	require.Equal(t, ring2, ring)

	ring.Entries.insert(entry{Token: dot10, Peer: peer1name})
	ring2.Entries = []*entry{{Token: start, Peer: peer1name, Free: 0}, {Token: dot10, Peer: peer1name}, {Token: dot245, Peer: peer1name}}
	require.Equal(t, ring2, ring)
}
开发者ID:rahulxkrishna,项目名称:weave,代码行数:18,代码来源:ring_test.go

示例7: TestEmptyReplay

func TestEmptyReplay(t *testing.T) {
	tMock := testingTMock{t, 0}

	dir, err := ioutil.TempDir("", "yarpcgorecorder")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(dir) // clean up

	recorder := NewRecorder(&tMock, RecordMode(Replay), RecordsPath(dir))

	withDisconnectedClient(t, recorder, func(client raw.Client) {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
		defer cancel()

		require.Panics(t, func() {
			client.Call(ctx, yarpc.NewReqMeta().Procedure("hello"), []byte("Hello"))
		})
		assert.Equal(t, tMock.fatalCount, 1)
	})
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:21,代码来源:recorder_test.go

示例8: TestInsert

func TestInsert(t *testing.T) {
	ring := New(start, end, peer1name)
	ring.Entries = []*entry{{Token: start, Peer: peer1name, Free: 255}}

	require.Panics(t, func() {
		ring.Entries.insert(entry{Token: start, Peer: peer1name})
	})

	ring.Entries.entry(0).Free = 0
	ring.Entries.insert(entry{Token: dot245, Peer: peer1name})
	check := []RangeInfo{
		{Peer: peer1name, Range: address.Range{Start: start, End: dot245}},
		{Peer: peer1name, Range: address.Range{Start: dot245, End: end}},
	}
	require.Equal(t, check, ring.AllRangeInfo())

	ring.Entries.insert(entry{Token: dot10, Peer: peer1name})
	check2 := []RangeInfo{
		{Peer: peer1name, Range: address.Range{Start: start, End: dot10}},
		{Peer: peer1name, Range: address.Range{Start: dot10, End: dot245}},
		{Peer: peer1name, Range: address.Range{Start: dot245, End: end}},
	}
	require.Equal(t, check2, ring.AllRangeInfo())
}
开发者ID:brb,项目名称:weave,代码行数:24,代码来源:ring_test.go

示例9: TestLeveledRWMutexIncorrect

func TestLeveledRWMutexIncorrect(t *testing.T) {
	mu1 := makeLeveledRWMutex(mutexLevel(testFirst), &sync.RWMutex{})
	mu2 := makeLeveledRWMutex(mutexLevel(testSecond), &sync.RWMutex{})
	mu3 := makeLeveledRWMutex(mutexLevel(testThird), &sync.RWMutex{})

	state := makeLevelState(testMutexLevelToString)

	mu2.RLock(state)
	defer mu2.RUnlock(state)

	// This must leave mu2 read-locked.
	require.Panics(t, func() {
		mu2.RLock(state)
	})

	// These must leave mu1 unlocked.
	require.Panics(t, func() {
		mu1.RLock(state)
	})
	require.Panics(t, func() {
		mu1.Lock(state)
	})

	mu3.Lock(state)
	defer mu3.Unlock(state)

	// This must leave mu3 locked.
	require.Panics(t, func() {
		mu3.RUnlock(state)
	})

	// These must leave mu2 read-locked.
	require.Panics(t, func() {
		mu2.Unlock(state)
	})
	require.Panics(t, func() {
		mu2.RUnlock(state)
	})
}
开发者ID:gozes,项目名称:kbfs-beta,代码行数:39,代码来源:leveled_mutex_test.go

示例10: TestSingletonToNonProviderPanics

func TestSingletonToNonProviderPanics(t *testing.T) {
	i := New()
	require.Panics(t, func() {
		i.MustBind(Singleton(1))
	})
}
开发者ID:alecthomas,项目名称:inject,代码行数:6,代码来源:inject_test.go

示例11: TestNewWorkItemRelationshipsLinksControllerDBNull

func TestNewWorkItemRelationshipsLinksControllerDBNull(t *testing.T) {
	require.Panics(t, func() {
		NewWorkItemRelationshipsLinksController(nil, nil)
	})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:5,代码来源:work-item-link-blackbox_test.go

示例12: TestNewWorkItemLinkControllerDBNull

func TestNewWorkItemLinkControllerDBNull(t *testing.T) {
	require.Panics(t, func() {
		NewWorkItemLinkController(nil, nil)
	})
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:5,代码来源:work-item-link-blackbox_test.go


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