當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。