Skip to content

Commit

Permalink
set evar for integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgsullivan committed Aug 5, 2022
1 parent 0d963c2 commit f3da556
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clean: clean-test-cache
clean-test-cache:
go clean -x -testcache

build: format test build-only
build: format unit-test build-only

build-only:
go build -x -o _exe/befehl cmd/main/main.go
Expand All @@ -21,6 +21,8 @@ unit-test: clean-test-cache
integration-test: clean-test-cache
scripts/test/run_integration_tests

test: unit-test integration-test

update-deps:
go get -u

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ You can configure befehl with a config file (~/.befehl.[toml|json|yaml]) any ser
```toml
[general]
logdir = "/home/ssullivan/log-special"
[auth]
privatekeyfile = "/home/ssullivan/alt/.ssh/id_rsa"
sshuser = "nonrootuser"
sshhostkeyverificationenabled = true
sshknownhostspath = "/home/asullivan/alt/.ssh/known_hosts"
[ssh]
privatekeyfile = "/home/ssullivan/alt/id_rsa"
user = "eingeben"
knownhostspath = "/home/asullivan/alt/.ssh/known_hosts"
hostkeyverificationenabled = true
```

Unless enabled as shown above, ssh known host verification is disabled.
Expand Down
14 changes: 8 additions & 6 deletions cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ Heres an example specifying all of the above mentioned options:
[general]
logdir = "/home/ssullivan/log-special"
[auth]
[ssh]
privatekeyfile = "/home/ssullivan/alt/id_rsa"
sshuser = "eingeben"
user = "eingeben"
knownhostspath = "/home/asullivan/alt/.ssh/known_hosts"
hostkeyverificationenabled = true
`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -43,12 +45,12 @@ sshuser = "eingeben"
}

instance := befehl.New(&befehl.Options{
PrivateKeyFile: Config.GetString("auth.privatekeyfile"),
SshUser: Config.GetString("auth.sshuser"),
PrivateKeyFile: Config.GetString("ssh.privatekeyfile"),
SshUser: Config.GetString("ssh.sshuser"),
LogDir: Config.GetString("general.logdir"),
SshHostKeyConfig: befehl.SshHostKeyConfig{
Enabled: Config.GetBool("auth.sshhostkeyverificationenabled"),
KnownHostsPath: Config.GetString("auth.sshknownhostspath"),
Enabled: Config.GetBool("ssh.hostkeyverificationenabled"),
KnownHostsPath: Config.GetString("ssh.knownhostspath"),
},
})

Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"strings"

"github.com/fatih/color"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,8 +39,12 @@ func initConfig() {
configDir = os.Getenv("BEFEHL_CONFIG_DIR")
}
thisViper.AddConfigPath(configDir)
thisViper.SetEnvPrefix("befehl")
thisViper.AutomaticEnv()
thisViper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
if err := thisViper.ReadInConfig(); err != nil {
fmt.Printf("Failed reading config (using defaults) [%s]: [%s]\n", thisViper.ConfigFileUsed(), err)
}

Config = thisViper
}
11 changes: 8 additions & 3 deletions integration_tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func buildApplication(cmdCancel chan bool, workDir string) error {
return nil
}

func runPayload(cmdCancel chan bool, workDir string) error {
func runPayload(cmdCancel chan bool, workDir string, evars []string) error {
if stdout, stderr, err := cmd.RunCmd(
"./_exe/befehl",
[]string{
Expand All @@ -30,7 +30,7 @@ func runPayload(cmdCancel chan bool, workDir string) error {
},
cmdCancel,
workDir,
[]string{},
evars,
); err != nil {
return fmt.Errorf("Failed running befehl execute: %s %s %s", stdout.String(), stderr.String(), err)
} else {
Expand Down Expand Up @@ -66,6 +66,11 @@ func TestIntegration(t *testing.T) {
}

workDir := pwd + "/.."
privateKeyPath := workDir + "/integration_tests/docker/ssh/id_rsa"
evars := []string{
fmt.Sprintf("BEFEHL_SSH_PRIVATEKEYFILE=%s", privateKeyPath),
}

cmdCancel := make(chan bool)

if err := buildApplication(cmdCancel, workDir); err != nil {
Expand All @@ -88,7 +93,7 @@ func TestIntegration(t *testing.T) {
}
}()

if err := runPayload(cmdCancel, workDir); err != nil {
if err := runPayload(cmdCancel, workDir, evars); err != nil {
t.Fatal(err)
}
}

0 comments on commit f3da556

Please sign in to comment.