func TestHackthing(t *testing.T) { fa := Flightaware{APIKey: TestAPIKey, APIUsername: TestAPIUsername} fa.Init() ret, err := fa.CallArrived("KSFO") if err != nil { t.Errorf("init call: %v", err) } for _, f := range ret { results, err := fa.CallFlightInfoEx(f.Ident) if err != nil { t.Errorf("CallFlightInfoEx failed: %v", err) } for _, v := range results { t := time.Unix(int64(v.Fileddeparturetime), 0) // Use v.actualdeparturetime to compare against arrived.actualdeparturetime if t.After(time.Now()) { continue } atoms := strings.Split(v.Route, " ") fmt.Printf("%s, %s-%s, %s, %s, %s\n", v.Ident, v.Origin, v.Destination, t, atoms[len(atoms)-1], v.Route) break } } }
func Test_MessageEntry_MessagesIsStored_And_GetsCorrectParameters(t *testing.T) { defer initCtrl(t)() a := assert.New(t) startTime := time.Now() msg := &guble.Message{Path: guble.Path("/topic1")} var storedMsg []byte var routedMsg *guble.Message routerMock := NewMockMessageSink(ctrl) messageEntry := NewMessageEntry(routerMock) messageStoreMock := NewMockMessageStore(ctrl) messageEntry.SetMessageStore(messageStoreMock) messageStoreMock.EXPECT().StoreTx("topic1", gomock.Any()). Do(func(topic string, callback func(msgId uint64) []byte) { storedMsg = callback(uint64(42)) }) routerMock.EXPECT().HandleMessage(gomock.Any()).Do(func(msg *guble.Message) { routedMsg = msg a.Equal(uint64(42), msg.Id) t, e := time.Parse(time.RFC3339, msg.PublishingTime) // publishing time a.NoError(e) a.True(t.After(startTime.Add(-1 * time.Second))) a.True(t.Before(time.Now().Add(time.Second))) }) messageEntry.HandleMessage(msg) a.Equal(routedMsg.Bytes(), storedMsg) }
// TestDimes tests the generation of durations and times. func TestTimes(t *testing.T) { assert := audit.NewTestingAssertion(t, true) gen := audit.NewGenerator(audit.SimpleRand()) for i := 0; i < 10000; i++ { // Test durations. lo := gen.Duration(time.Second, time.Minute) hi := gen.Duration(time.Second, time.Minute) d := gen.Duration(lo, hi) if hi < lo { lo, hi = hi, lo } assert.True(lo <= d && d <= hi) // Test times. loc := time.Local now := time.Now() dur := gen.Duration(24*time.Hour, 30*24*time.Hour) t := gen.Time(loc, now, dur) assert.True(t.Equal(now) || t.After(now)) assert.True(t.Before(now.Add(dur)) || t.Equal(now.Add(dur))) } }