示例#1
0
func TestLinkedSubscription(t *testing.T) {
	linked := NewLinkedSubscription()
	sub := NewGenericSubscription()
	assert.False(t, linked.Disposed())
	assert.False(t, sub.Disposed())
	linked.Link(sub)
	assert.Panics(t, func() { linked.Link(sub) })
	linked.Dispose()
	assert.True(t, sub.Disposed())
	assert.True(t, linked.Disposed())
}
示例#2
0
func Test_Renewal(t *testing.T) {
	res := &http.Response{
		StatusCode: 400,
	}
	assert.True(t, needsRenewal(res, nil))

	res.StatusCode = 200
	assert.False(t, needsRenewal(res, nil))
}
示例#3
0
func TestNegativePrefixLongFlag(t *testing.T) {
	fg := newFlagGroup()
	f := fg.Flag("no-comment", "")
	b := f.Bool()
	fg.init("")
	tokens := tokenize([]string{"--no-comment"}, false)
	_, err := fg.parse(tokens)
	assert.NoError(t, err)
	assert.False(t, *b)
}
示例#4
0
func TestNoBool(t *testing.T) {
	fg := newFlagGroup()
	f := fg.Flag("b", "").Default("true")
	b := f.Bool()
	fg.init("")
	tokens := tokenize([]string{"--no-b"}, false)
	_, err := fg.parse(tokens)
	assert.NoError(t, err)
	assert.False(t, *b)
}
示例#5
0
func TestLinkedSubscriptionUnsubscribesTargetOnLink(t *testing.T) {
	linked := NewLinkedSubscription()
	sub := NewGenericSubscription()
	linked.Dispose()
	assert.True(t, linked.Disposed())
	assert.False(t, sub.Disposed())
	linked.Link(sub)
	assert.True(t, linked.Disposed())
	assert.True(t, sub.Disposed())
}
示例#6
0
func TestCombinedShortFlags(t *testing.T) {
	app := newTestApp()
	a := app.Flag("short0", "").Short('0').Bool()
	b := app.Flag("short1", "").Short('1').Bool()
	c := app.Flag("short2", "").Short('2').Bool()
	_, err := app.Parse([]string{"-01"})
	assert.NoError(t, err)
	assert.True(t, *a)
	assert.True(t, *b)
	assert.False(t, *c)
}
示例#7
0
func TestChannelSubscription(t *testing.T) {
	done := make(chan bool)
	unsubscribed := false
	var s Subscription = NewChannelSubscription()
	events, ok := s.(SubscriptionEvents)
	assert.True(t, ok)
	events.OnUnsubscribe(func() { unsubscribed = true; done <- true })
	assert.False(t, s.Disposed())
	s.Dispose()
	assert.True(t, s.Disposed())
	<-done
	assert.True(t, unsubscribed)
}
示例#8
0
文件: eos_test.go 项目: itchio/wharf
func Test_OpenEmptyFile(t *testing.T) {
	f, err := Open("/dev/null")
	assert.NoError(t, err)

	s, err := f.Stat()
	assert.NoError(t, err)

	assert.EqualValues(t, 0, s.Size())
	assert.False(t, s.IsDir())
	assert.EqualValues(t, "/dev/null", s.Name())
	assert.Nil(t, s.Sys())
	assert.EqualValues(t, 0644, s.Mode())
	assert.EqualValues(t, time.Time{}, s.ModTime())

	buf := make([]byte, 1)

	_, err = f.Read(buf)
	assert.Error(t, err)

	_, err = f.ReadAt(buf, 0)
	assert.Error(t, err)

	assert.NoError(t, f.Close())
}
示例#9
0
func TestUnsubscribe(t *testing.T) {
	s := NewGenericSubscription()
	assert.False(t, s.Disposed())
	s.Dispose()
	assert.True(t, s.Disposed())
}