本文整理汇总了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")
}
示例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()
})
}
示例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)
})
}
示例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)
})
}
示例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"))
})
}
示例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)
}
示例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)
})
}
示例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())
}
示例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)
})
}
示例10: TestSingletonToNonProviderPanics
func TestSingletonToNonProviderPanics(t *testing.T) {
i := New()
require.Panics(t, func() {
i.MustBind(Singleton(1))
})
}
示例11: TestNewWorkItemRelationshipsLinksControllerDBNull
func TestNewWorkItemRelationshipsLinksControllerDBNull(t *testing.T) {
require.Panics(t, func() {
NewWorkItemRelationshipsLinksController(nil, nil)
})
}
示例12: TestNewWorkItemLinkControllerDBNull
func TestNewWorkItemLinkControllerDBNull(t *testing.T) {
require.Panics(t, func() {
NewWorkItemLinkController(nil, nil)
})
}