diff options
| author | Paul Buetow <paul@buetow.org> | 2021-10-24 13:34:06 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-10-24 13:34:19 +0300 |
| commit | 14959ffba46282dd7b8ada53db0dfc0e1b26ab2e (patch) | |
| tree | 0b207cb61af3aa2bd93a0c5c864ec91246dd4595 /internal/config | |
| parent | ac2d6fa5d054ca725a7268eb1a8e050525372c34 (diff) | |
Fix DCat color test.
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/client.go | 3 | ||||
| -rw-r--r-- | internal/config/env.go | 20 | ||||
| -rw-r--r-- | internal/config/initializer.go | 6 |
3 files changed, 23 insertions, 6 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..8d617f2 100644 --- a/internal/config/initializer.go +++ b/internal/config/initializer.go @@ -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") } } |
