2021-10-11 23:11:45 +03:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2021-11-16 04:47:05 +03:00
|
|
|
"testing"
|
|
|
|
|
2021-10-11 23:11:45 +03:00
|
|
|
testutils "github.com/Azure/azure-container-networking/test/utils"
|
|
|
|
utilexec "k8s.io/utils/exec"
|
2021-11-16 04:47:05 +03:00
|
|
|
testingexec "k8s.io/utils/exec/testing"
|
2021-10-11 23:11:45 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type IOShim struct {
|
|
|
|
Exec utilexec.Interface
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIOShim() *IOShim {
|
|
|
|
return &IOShim{
|
|
|
|
Exec: utilexec.New(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMockIOShim(calls []testutils.TestCmd) *IOShim {
|
|
|
|
return &IOShim{
|
|
|
|
Exec: testutils.GetFakeExecWithScripts(calls),
|
|
|
|
}
|
|
|
|
}
|
2021-11-16 04:47:05 +03:00
|
|
|
|
|
|
|
// VerifyCalls is used for Unit Testing with a mock ioshim. It asserts that the number of calls made is equal to the number given to the mock ioshim.
|
|
|
|
func (ioshim *IOShim) VerifyCalls(t *testing.T, calls []testutils.TestCmd) {
|
|
|
|
fexec, couldCast := ioshim.Exec.(*testingexec.FakeExec)
|
|
|
|
if couldCast {
|
|
|
|
testutils.VerifyCalls(t, fexec, calls)
|
|
|
|
}
|
|
|
|
}
|