summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorPaul Buetow <35781042+pbuetow@users.noreply.github.com>2021-10-24 18:05:47 +0300
committerGitHub <noreply@github.com>2021-10-24 18:05:47 +0300
commit3d24204754aff155de21b01e9e3d82eb460fb87f (patch)
tree093fb4bff0bdf086188df86ca5d13dc7f8a34e4f /internal/config
parent6edea198188172c603e10201aa2302a28b7b722f (diff)
parent6cfc4e161f94ab159d4b1ea491ffe6f166fa6204 (diff)
Merge pull request #24 from snonux/develop
Bugfixes around integration tests
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/client.go3
-rw-r--r--internal/config/env.go20
-rw-r--r--internal/config/initializer.go8
3 files changed, 24 insertions, 7 deletions
diff --git a/internal/config/client.go b/internal/config/client.go
index 86f97f0..9f4df97 100644
--- a/internal/config/client.go
+++ b/internal/config/client.go
@@ -104,9 +104,6 @@ type termColors struct {
type ClientConfig struct {
TermColorsEnable bool `json:",omitempty"`
TermColors termColors `json:",omitempty"`
- // When unit testing in Jenkins you don't want to touch files in ~jenkins
- // during integration tests really.
- SSHDontAddHostsToKnownHostsFile bool `json:",omitempty"`
}
// Create a new default client configuration.
diff --git a/internal/config/env.go b/internal/config/env.go
index 88b831d..804a10a 100644
--- a/internal/config/env.go
+++ b/internal/config/env.go
@@ -2,6 +2,26 @@ package config
import "os"
+// Env returns true when a given environment variable is set to "yes".
func Env(env string) bool {
return "yes" == os.Getenv(env)
}
+
+// Hostname returns the current hostname. It can be overriden with
+// DTAIL_HOSTNAME_OVERRIDE environment variable (useful for integration tests).
+func Hostname() (string, error) {
+ hostname := os.Getenv("DTAIL_HOSTNAME_OVERRIDE")
+ if len(hostname) > 0 {
+ return hostname, nil
+ }
+ return os.Hostname()
+}
+
+// SSHKnownHostsFile returns the known hosts file path (useful for integration tests)
+func SSHKnownHostsFile() string {
+ if len(os.Getenv("DTAIL_SSH_KNOWN_HOSTS_FILE")) > 0 {
+ return os.Getenv("DTAIL_SSH_KNOWN_HOSTS_FILE")
+ } else {
+ return os.Getenv("HOME") + "/.ssh/known_hosts"
+ }
+}
diff --git a/internal/config/initializer.go b/internal/config/initializer.go
index 4d6a73b..024464e 100644
--- a/internal/config/initializer.go
+++ b/internal/config/initializer.go
@@ -21,7 +21,7 @@ type initializer struct {
type transformCb func(*initializer, *Args, []string) error
func (in *initializer) parseConfig(args *Args) error {
- if strings.ToUpper(args.ConfigFile) == "NONE" {
+ if strings.ToLower(args.ConfigFile) == "none" {
return nil
}
@@ -82,9 +82,9 @@ func (in *initializer) transformConfig(sourceProcess source.Source, args *Args,
// There are some special options which can be set by environment variable.
func (in *initializer) readEnvironmentVars() {
- if Env("DTAIL_SSH_DONT_ADD_HOSTS_TO_KNOWNHOSTS_FILE") ||
- Env("DTAIL_JENKINS") {
- in.Client.SSHDontAddHostsToKnownHostsFile = true
+ if Env("DTAIL_RUN_INTEGRATION_TESTS") {
+ os.Setenv("DTAIL_HOSTNAME_OVERRIDE", "integrationtest")
+ os.Setenv("DTAIL_SSH_KNOWN_HOSTS_FILE", "./known_hosts")
}
}