Skip to content

Commit

Permalink
coverage: Processes unit tests missing + improve global coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rbeuque74 committed May 11, 2018
1 parent 082bca9 commit 2ef8d0c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion consumers/nsca/nsca.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ func (consumer Consumer) Unload() {
}

log.Debugf("consumer: sent 'quit' information to receiver")
consumer.exitChannel <- true
close(consumer.exitChannel)
}
2 changes: 1 addition & 1 deletion consumers/nsca/nsca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestConsumerSendMessage(t *testing.T) {
t.Log("nsca send OK")
}
messageReceived = true
close(exitCh)
consumer.Unload()
case <-time.After(time.Second):
t.Log("timed out")
if !messageReceived {
Expand Down
3 changes: 3 additions & 0 deletions plugins/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func TestCommand(t *testing.T) {
checker, err := NewCommandChecker(cfg, nil)
assert.Nilf(t, err, "command checker instantiation failed: %q", err)

assert.Equal(t, "Command", checker.Name())
assert.Equal(t, "test-1", checker.ServiceName())

ctxRun, cancelFunc1 := context.WithTimeout(context.Background(), time.Second)
defer cancelFunc1()
result := checker.Run(ctxRun)
Expand Down
3 changes: 3 additions & 0 deletions plugins/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func TestHTTPServer(t *testing.T) {
checker, err := NewHTTPChecker(cfg, nil)
assert.Nilf(t, err, "http checker instantiation failed: %q", err)

assert.Equal(t, "HTTP", checker.Name())
assert.Equal(t, "test-1", checker.ServiceName())

ctxRun, cancelFunc1 := context.WithTimeout(context.Background(), time.Second)
defer cancelFunc1()

Expand Down
33 changes: 33 additions & 0 deletions plugins/processes/processes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ func startProcesses(t *testing.T) {
}

pids = append(pids, cmd.Process)

cmd = exec.Command("/bin/sleep", "13")

if err := cmd.Start(); err != nil {
t.Error(err)
t.FailNow()
}

pids = append(pids, cmd.Process)

cmd = exec.Command("/bin/sleep", "13")

if err := cmd.Start(); err != nil {
t.Error(err)
t.FailNow()
}

pids = append(pids, cmd.Process)
}

func stopProcesses(t *testing.T) {
Expand Down Expand Up @@ -59,6 +77,9 @@ func TestProcesses(t *testing.T) {
checker, err := NewProcessesChecker(cfg, nil)
assert.Nilf(t, err, "processes checker instantiation failed: %q", err)

assert.Equal(t, "Processes", checker.Name())
assert.Equal(t, "test-1", checker.ServiceName())

ctxRun, cancelFunc1 := context.WithTimeout(context.Background(), time.Second)
defer cancelFunc1()
result := checker.Run(ctxRun)
Expand Down Expand Up @@ -114,4 +135,16 @@ func TestProcesses(t *testing.T) {
result = checker.Run(ctxRun)
assert.Equal(t, plugins.STATE_CRITICAL, result.Status)
assert.Equal(t, "Process /bin/sleep is not running", result.Message, "processes bad message: %q", result.Message)

// partial args
cfg["args"] = "13"

checker, err = NewProcessesChecker(cfg, nil)
assert.Nilf(t, err, "processes checker instantiation failed: %q", err)

ctxRun, cancelFunc1 = context.WithTimeout(context.Background(), time.Second)
defer cancelFunc1()
result = checker.Run(ctxRun)
assert.Equal(t, plugins.STATE_WARNING, result.Status)
assert.Equal(t, "Process /bin/sleep 13 have too many instances running", result.Message)
}
2 changes: 1 addition & 1 deletion plugins/supervisor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func loadConfiguration(conf interface{}) (checkerConfig, error) {
}

if cfg.Service != nil && cfg.Type == "services" {
return cfg, fmt.Errorf("type 'servicess' and service key are incompatible")
return cfg, fmt.Errorf("type 'services' and service key are incompatible")
}

return cfg, nil
Expand Down
3 changes: 3 additions & 0 deletions plugins/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func TestSupervisor(t *testing.T) {
checker, err := NewSupervisorChecker(cfg, pluginCfg)
assert.Nilf(t, err, "command checker instantiation failed: %q", err)

assert.Equal(t, "Supervisor", checker.Name())
assert.Equal(t, "test-1", checker.ServiceName())

ctxRun, cancelFunc1 := context.WithTimeout(context.Background(), time.Second)
defer cancelFunc1()
result := checker.Run(ctxRun)
Expand Down

0 comments on commit 2ef8d0c

Please sign in to comment.