Skip to content

Commit

Permalink
Add tests for noop components
Browse files Browse the repository at this point in the history
  • Loading branch information
johandroz committed Mar 25, 2018
1 parent 7df0a2f commit 6c72c32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions internal/keycloakd/instrumenting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,27 @@ func TestMetrics(t *testing.T) {

mockInflux.EXPECT().Ping(1*time.Second).Return(time.Duration(0), "", nil).Times(1)
influxMetrics.Ping(1 * time.Second)

mockInflux.EXPECT().Write(nil).Return(nil).Times(1)
influxMetrics.Write(nil)
}

func TestNoopMetrics(t *testing.T) {
var noopMetrics = &NoopMetrics{}

assert.Nil(t, noopMetrics.Write(nil))

var counter = noopMetrics.NewCounter("counter name")
assert.IsType(t, &NoopCounter{}, counter)
assert.IsType(t, &NoopCounter{}, counter.With())

var gauge = noopMetrics.NewGauge("gauge name")
assert.IsType(t, &NoopGauge{}, gauge)
assert.IsType(t, &NoopGauge{}, gauge.With())

var histogram = noopMetrics.NewHistogram("histogram name")
assert.IsType(t, &NoopHistogram{}, histogram)
assert.IsType(t, &NoopHistogram{}, histogram.With())

var duration, s, err = noopMetrics.Ping(1 * time.Second)
assert.Equal(t, time.Duration(0), duration)
Expand Down
18 changes: 16 additions & 2 deletions internal/keycloakd/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestLogstashEncode(t *testing.T) {
"msg": "logstash log",
"caller": "flakid.go:120",
"component_name": "flaki-service",
"component_version": "1.0.0",
"component_version": "1.0",
"environment": "DEV",
"git_commit": "5fb7de0d7ae3f3d5f5d6a322b2344bdab645fd33",
"ts": "2018-02-13T06:27:07.123915229Z",
Expand All @@ -45,11 +45,25 @@ func TestLogstashEncode(t *testing.T) {
var fields = m["@fields"].(map[string]interface{})
assert.Equal(t, "flakid.go:120", fields["caller"])
assert.Equal(t, "flaki-service", fields["component_name"])
assert.Equal(t, "1.0.0", fields["component_version"])
assert.Equal(t, "1.0", fields["component_version"])
assert.Equal(t, "DEV", fields["environment"])
assert.Equal(t, "5fb7de0d7ae3f3d5f5d6a322b2344bdab645fd33", fields["git_commit"])
var _, ok = fields["ts"]
assert.False(t, ok)
_, ok = fields["msg"]
assert.False(t, ok)
}

func TestNoopRedis(t *testing.T) {
var noopRedis = &NoopRedis{}

assert.Nil(t, noopRedis.Close())

var reply, err = noopRedis.Do("")
assert.Nil(t, reply)
assert.Nil(t, err)

assert.Nil(t, noopRedis.Send(""))

assert.Nil(t, noopRedis.Flush())
}

0 comments on commit 6c72c32

Please sign in to comment.