-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added default executor modifiable for tests.
The executor abstraction allows us to introduce a mock executor, which removes the need for VBoxManage installed on the box, as well as introducting various failure scenarios which could then be tested and improve the reliability of the project. With the current implementation, the mock executor always returns nil, and allows all tests to pass. This behaviour should be changed in the future, perhaps adapted even more with closures to allow the list of items that should be returned as output.
- Loading branch information
1 parent
2576aa8
commit f8abf83
Showing
2 changed files
with
54 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
package virtualbox | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func init() { | ||
Verbose = true | ||
} | ||
|
||
func TestVBMOut(t *testing.T) { | ||
b, err := vbmOut("list", "vms") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Logf("%s", b) | ||
} | ||
|
||
func setup() { | ||
Verbose = true | ||
|
||
defaultExecutor = mockExecutor | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
setup() | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func mockExecutor(ctx context.Context, so io.Writer, se io.Writer, args ...string) error { | ||
// TODO: By returning nil we are causing all the tests to pass because the | ||
// current ones do not check the output of the command. Here we would | ||
// keep the state of the machines, immitating VBoxManage - thus | ||
// eliminating it as a dependency. | ||
return nil | ||
} |