func setup(t *testing.T) (*amqpConnector, *MockamqpChannel, func()) { mockCtrl := gomock.NewController(t) mockChannel := NewMockamqpChannel(mockCtrl) ac := amqpConnector{ chMaker: mockChannelMaker{ channel: mockChannel, }, queueName: "fooqueue", retryTimeoutBase: time.Second, } return &ac, mockChannel, func() { mockCtrl.Finish() } }
func TestScopedStatsStatsd(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() statter := NewMockStatter(ctrl) stats := NewStatsdScope(statter, "fake") statter.EXPECT().Inc("fake.counter", int64(2), float32(1.0)).Return(nil) stats.Inc("counter", 2) statter.EXPECT().Dec("fake.counter", int64(2), float32(1.0)).Return(nil) stats.Dec("counter", 2) statter.EXPECT().Gauge("fake.gauge", int64(2), float32(1.0)).Return(nil) stats.Gauge("gauge", 2) statter.EXPECT().GaugeDelta("fake.delta", int64(2), float32(1.0)).Return(nil) stats.GaugeDelta("delta", 2) statter.EXPECT().Timing("fake.latency", int64(2), float32(1.0)).Return(nil) stats.Timing("latency", 2) statter.EXPECT().TimingDuration("fake.latency", 2*time.Second, float32(1.0)).Return(nil) stats.TimingDuration("latency", 2*time.Second) statter.EXPECT().Set("fake.something", "value", float32(1.0)).Return(nil) stats.Set("something", "value") statter.EXPECT().SetInt("fake.someint", int64(10), float32(1.0)).Return(nil) stats.SetInt("someint", 10) statter.EXPECT().Raw("fake.raw", "raw value", float32(1.0)).Return(nil) stats.Raw("raw", "raw value") s := stats.NewScope("foobar") statter.EXPECT().Inc("fake.foobar.counter", int64(3), float32(1.0)).Return(nil) s.Inc("counter", 3) ss := stats.NewScope("another", "level") statter.EXPECT().Inc("fake.foobar.counter", int64(4), float32(1.0)).Return(nil) s.Inc("counter", 4) if stats.Scope() != "fake" { t.Errorf(`expected "fake", got %#v`, stats.Scope()) } if s.Scope() != "fake.foobar" { t.Errorf(`expected "fake.foobar", got %#v`, s.Scope()) } if ss.Scope() != "fake.another.level" { t.Errorf(`expected "fake.foobar", got %#v`, s.Scope()) } twoScope := NewStatsdScope(statter, "fake", "bang") statter.EXPECT().Inc("fake.bang.counter", int64(7), float32(1.0)).Return(nil) twoScope.Inc("counter", 7) }
func TestIsSafeDomain(t *testing.T) { // TODO(jmhodges): use more of the GSB lib by teaching it how to not make // http requests // This test is mocked out at the wrong level (SafeBrowsing) because the gsb lib // we rely on is a little funny and overcomplicated, but still hasn't // learned out how not make HTTP requests in tests. stats, _ := statsd.NewNoopClient() ctrl := gomock.NewController(t) defer ctrl.Finish() sbc := NewMockSafeBrowsing(ctrl) sbc.EXPECT().IsListed("good.com").Return("", nil) sbc.EXPECT().IsListed("bad.com").Return("bad", nil) sbc.EXPECT().IsListed("errorful.com").Return("", errors.New("welp")) sbc.EXPECT().IsListed("outofdate.com").Return("", safebrowsing.ErrOutOfDateHashes) va := NewValidationAuthorityImpl(&PortConfig{}, sbc, stats, clock.NewFake()) resp, err := va.IsSafeDomain(&core.IsSafeDomainRequest{Domain: "good.com"}) if err != nil { t.Errorf("good.com: want no error, got '%s'", err) } if !resp.IsSafe { t.Errorf("good.com: want true, got %t", resp.IsSafe) } resp, err = va.IsSafeDomain(&core.IsSafeDomainRequest{Domain: "bad.com"}) if err != nil { t.Errorf("bad.com: want no error, got '%s'", err) } if resp.IsSafe { t.Errorf("bad.com: want false, got %t", resp.IsSafe) } _, err = va.IsSafeDomain(&core.IsSafeDomainRequest{Domain: "errorful.com"}) if err == nil { t.Errorf("errorful.com: want error, got none") } resp, err = va.IsSafeDomain(&core.IsSafeDomainRequest{Domain: "outofdate.com"}) if err != nil { t.Errorf("outofdate.com: want no error, got '%s'", err) } if !resp.IsSafe { t.Errorf("outofdate.com: IsSafeDomain should fail open on out of date hashes") } }