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()) }
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)) }
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) }
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) }
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()) }
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) }
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) }
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()) }
func TestUnsubscribe(t *testing.T) { s := NewGenericSubscription() assert.False(t, s.Disposed()) s.Dispose() assert.True(t, s.Disposed()) }