refact(e2e): Use envconfig's required property
This commit is contained in:
1 parent
da0fb9d38a
commit
0afef63dca
5 files changed
+20
-143
No files matched your search
@@ -3,7 +3,6 @@ package vault_test
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -25,30 +24,13 @@ import (
|
||||
)
|
||||
|
||||
type config struct {
|
||||
TargetIp string `envconfig:"E2E_TARGET_IP"` // e.g. 192.168.0.1
|
||||
TargetSshUser string `envconfig:"E2E_SSH_USER"` // e.g. ubuntu
|
||||
TargetSshKeyPath string `envconfig:"E2E_SSH_KEY_PATH"` // e.g. /Users/username/key.pem
|
||||
TargetIp string `envconfig:"E2E_TARGET_IP" required:"true"` // e.g. 192.168.0.1
|
||||
TargetSshUser string `envconfig:"E2E_SSH_USER" required:"true"` // e.g. ubuntu
|
||||
TargetSshKeyPath string `envconfig:"E2E_SSH_KEY_PATH" required:"true"` // e.g. /Users/username/key.pem
|
||||
TargetPort string `envconfig:"E2E_SSH_PORT" default:"22"`
|
||||
VaultSecretPath string `envconfig:"E2E_VAULT_SECRET_PATH" default:"e2e_secrets"`
|
||||
}
|
||||
|
||||
func (c *config) validate() error {
|
||||
if c.TargetIp == "" {
|
||||
return errors.New("TargetIp is empty. Set environment variable: E2E_TARGET_IP")
|
||||
}
|
||||
if c.TargetSshUser == "" {
|
||||
return errors.New("TargetSshUser is empty. Set environment variable: E2E_SSH_USER")
|
||||
}
|
||||
if c.TargetSshKeyPath == "" {
|
||||
return errors.New("TargetSshKeyPath is empty. Set environment variable: E2E_SSH_KEY_PATH")
|
||||
}
|
||||
if c.TargetPort == "" {
|
||||
return errors.New("TargetPort is empty. Set environment variable: E2E_SSH_PORT")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadConfig() (*config, error) {
|
||||
var c config
|
||||
err := envconfig.Process("", &c)
|
||||
@@ -56,11 +38,6 @@ func loadConfig() (*config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = c.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &c, err
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user