Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
pre and post exec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtodzo committed Nov 23, 2020
1 parent 5f81f0c commit 224ea4a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions run_bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,55 @@ func TestCoverageCollector_writeArgs(t *testing.T) {
}
}

func TestPreAndPostExec(t *testing.T) {
tests := []struct {
name string
preCmdFuncs int
postCmdFuncs int
}{
{
name: "add two preCmdFuncs and one postCmdFunc",
preCmdFuncs: 2,
postCmdFuncs: 1,
},
{
name: "add zero preCmdFuncs and two postCmdFunc",
preCmdFuncs: 0,
postCmdFuncs: 1,
},
{
name: "zero cmdFuncs",
preCmdFuncs: 0,
postCmdFuncs: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var preCmdFuncs []CmdFunc
for i := 0; i < tt.preCmdFuncs; i++ {
preCmdFuncs = append(preCmdFuncs, func(cmd *exec.Cmd) error {
return nil
})
}
var postCmdFuncs []CmdFunc
for j := 0; j < tt.postCmdFuncs; j++ {
postCmdFuncs = append(postCmdFuncs, func(cmd *exec.Cmd) error {
return nil
})
}
c := NewCoverageCollector("", false)
var options []CoverageCollectorOption
options = append(options, PreExec(preCmdFuncs...))
options = append(options, PostExec(postCmdFuncs...))
for _, option := range options {
option(c)
}
require.Equal(t, tt.preCmdFuncs, len(c.preCmdFuncs))
require.Equal(t, tt.postCmdFuncs, len(c.postCmdFuncs))
})
}
}

func TestCoverageCollector_RunBinary(t *testing.T) {
type fields struct {
MergedCoverageFilename string
Expand Down

0 comments on commit 224ea4a

Please sign in to comment.