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