forked from hashicorp/otto
/
dev_testing.go
55 lines (47 loc) · 1.43 KB
/
dev_testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package vagrant
import (
"log"
"github.com/hashicorp/otto/otto"
)
// DevTestTeardown implements the otto.TestTeardownFunc type and should
// be used with otto.TestCase to clear out development environments cleanly.
func DevTestTeardown(c *otto.Core) error {
// Destroy the dev environment. This should work even if it isn't
// running so we can always execute it.
log.Printf("[INFO] test: destroying the development environment")
err := c.Execute(&otto.ExecuteOpts{
Task: otto.ExecuteTaskDev,
Action: "destroy",
})
if err != nil {
return err
}
// Delete all the layers
return c.Execute(&otto.ExecuteOpts{
Task: otto.ExecuteTaskDev,
Action: "layers",
Args: []string{"-prune"},
})
}
// DevTestStepInit is a otto.TestStep that initilizes dev testing.
// This should be the first test step before any others for dev.
type DevTestStepInit struct{}
func (s *DevTestStepInit) Run(c *otto.Core) error {
log.Printf("[INFO] test: starting the development environment")
return c.Dev()
}
// DevTestStepGuestScript is an otto.TestStep that runs a script in the
// guest and verifies it succeeds (exit code 0).
type DevTestStepGuestScript struct {
Command string
}
func (s *DevTestStepGuestScript) Run(c *otto.Core) error {
log.Printf("[INFO] test: testing guest script: %q", s.Command)
return c.Execute(&otto.ExecuteOpts{
Task: otto.ExecuteTaskDev,
Action: "vagrant",
Args: []string{
"ssh", "-c", s.Command,
},
})
}