Skip to content

Commit

Permalink
fix(engine): test execution of declarative commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasfrahm committed Apr 23, 2022
1 parent 0f9bbc7 commit 07dd8b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions pkg/engine/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package engine
14 changes: 13 additions & 1 deletion pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"sync"

"github.com/nicklasfrahm/k3se/pkg/sshx"
"github.com/rs/zerolog"
)

Expand Down Expand Up @@ -78,5 +79,16 @@ func (e *Engine) Configure(node *Node) error {

// Cleanup removes all temporary files from the node.
func (e *Engine) Cleanup(node *Node) error {
return node.Run("rm -rf /tmp/k3se")
if err := node.Do(sshx.Cmd{
Cmd: "echo $MYVAR > ~/test.txt",
Env: map[string]string{
"MYVAR": "hello",
},
}); err != nil {
return err
}

return node.Do(sshx.Cmd{
Cmd: "rm -rf /tmp/k3se",
})
}
16 changes: 3 additions & 13 deletions pkg/engine/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,7 @@ func (node *Node) Upload(dst string, src io.Reader) error {
return err
}

// Run executes the specified command on the node.
func (node *Node) Run(cmd string) error {
session, err := node.Client.SSH.NewSession()
if err != nil {
return err
}
defer session.Close()

if err := session.Run(cmd); err != nil {
return err
}

return nil
// Do executes a command on the node.
func (node *Node) Do(cmd sshx.Cmd) error {
return node.Client.Do(cmd)
}

0 comments on commit 07dd8b5

Please sign in to comment.