Skip to content

Commit

Permalink
queue unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgsullivan committed Aug 4, 2022
1 parent 810b645 commit e632036
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion befehl.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (instance *Instance) executePayloadOnHosts(payload []byte, hostsFilePath st
go func() {
instance.runPayload(&wg, host, payload, sshConfig)
<-hostsChan
remaining := queue.decrementCounter(hostCnt)
remaining := queue.decrementCounter()
color.Magenta(fmt.Sprintf("Remaining: %d / %d\n", remaining, hostCnt))
}()
}
Expand Down
2 changes: 1 addition & 1 deletion queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func (q *queue) New(hostCnt int64) *queue {
}
}

func (q *queue) decrementCounter(total int) int64 {
func (q *queue) decrementCounter() int64 {
return atomic.AddInt64(&q.count, -1)
}
23 changes: 23 additions & 0 deletions queue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package befehl

import (
"testing"
)

func TestNew(t *testing.T) {
q := new(queue).New(42)
if q.count != 42 {
t.Fatalf("count value of %d is unexpected", q.count)
}
}

func TestDecrementCounter(t *testing.T) {
q := new(queue).New(42)
newCount := q.decrementCounter()
if q.count != 41 {
t.Fatalf("count value of %d is unexpected", q.count)
}
if newCount != 41 {
t.Fatalf("newCount of %d is unexpected", newCount)
}
}

0 comments on commit e632036

Please sign in to comment.