add sharness test

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy 2016-02-01 16:35:22 -08:00
parent 366d7db3d3
commit c7c1e72eaf
3 changed files with 54 additions and 5 deletions

View File

@ -45,7 +45,6 @@ func (rl *ReqLog) Add(req Request) *ReqLogEntry {
rl.lock.Lock()
defer rl.lock.Unlock()
log.Error("ADD: ", req)
rle := &ReqLogEntry{
StartTime: time.Now(),
Active: true,
@ -95,8 +94,6 @@ func (rl *ReqLog) Report() []*ReqLogEntry {
defer rl.lock.Unlock()
out := make([]*ReqLogEntry, len(rl.Requests))
log.Error("REPORT: ", rl.Requests)
for i, e := range rl.Requests {
out[i] = e.Copy()
}

View File

@ -33,9 +33,9 @@ Lists running and recently run commands.
fmt.Fprintln(w, "Command\tActive\tStartTime\tRunTime")
for _, req := range *out {
if req.Active {
fmt.Fprintf(w, "%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
} else {
fmt.Fprintf(w, "%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
}
}
w.Flush()

View File

@ -0,0 +1,52 @@
#!/bin/sh
#
# Copyright (c) 2016 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test active request commands"
. lib/test-lib.sh
test_init_ipfs
test_launch_ipfs_daemon
test_expect_success "command works" '
ipfs diag cmds > cmd_out
'
test_expect_success "invoc shows up in output" '
grep "diag/cmds" cmd_out > /dev/null
'
test_expect_success "start longer running command" '
ipfs log tail &
LOGPID=$!
'
test_expect_success "long running command shows up" '
ipfs diag cmds > cmd_out2
'
test_expect_success "output looks good" '
grep "log/tail" cmd_out2 | grep "true" > /dev/null
'
test_expect_success "kill log cmd" '
kill $LOGPID
go-sleep 0.5s
kill $LOGPID
wait $LOGPID || true
'
test_expect_success "long running command inactive" '
ipfs diag cmds > cmd_out3
'
test_expect_success "command shows up as inactive" '
grep "log/tail" cmd_out3 | grep "false"
'
test_kill_ipfs_daemon
test_done