Test missing-config errors in pburl and pblastreport
This commit is contained in:
@@ -23,10 +23,17 @@ import (
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
if err := execute(os.Args[1:]); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// execute builds and runs the CLI; cobra prints any returned error.
|
||||
func execute(args []string) error {
|
||||
cfg, err := puppet.Load()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "config error:", err)
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -94,7 +101,6 @@ func main() {
|
||||
SilenceUsage: true,
|
||||
})
|
||||
|
||||
if err := root.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
root.SetArgs(args)
|
||||
return root.Execute()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"node-lookup/internal/puppet"
|
||||
)
|
||||
|
||||
func TestExecute_MissingConfigNamesBothKeys(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("XDG_CONFIG_HOME", dir)
|
||||
t.Setenv("NODE_LOOKUP_URL", "")
|
||||
t.Setenv("NODE_LOOKUP_PUPPETBOARD_URL", "")
|
||||
old := puppet.SystemConfigPath
|
||||
puppet.SystemConfigPath = filepath.Join(dir, "etc-config.yaml")
|
||||
t.Cleanup(func() { puppet.SystemConfigPath = old })
|
||||
|
||||
err := execute([]string{"host1"})
|
||||
if err == nil || !strings.Contains(err.Error(), "puppetdb_url") || !strings.Contains(err.Error(), "puppetboard_url") {
|
||||
t.Fatalf("expected missing puppetdb_url and puppetboard_url error, got %v", err)
|
||||
}
|
||||
}
|
||||
+10
-4
@@ -19,10 +19,17 @@ import (
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
if err := execute(os.Args[1:]); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// execute builds and runs the CLI; cobra prints any returned error.
|
||||
func execute(args []string) error {
|
||||
cfg, err := puppet.Load()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "config error:", err)
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
|
||||
var boardURL string
|
||||
@@ -60,7 +67,6 @@ func main() {
|
||||
SilenceUsage: true,
|
||||
})
|
||||
|
||||
if err := root.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
root.SetArgs(args)
|
||||
return root.Execute()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"node-lookup/internal/puppet"
|
||||
)
|
||||
|
||||
func TestExecute_MissingPuppetboardURL(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("XDG_CONFIG_HOME", dir)
|
||||
t.Setenv("NODE_LOOKUP_PUPPETBOARD_URL", "")
|
||||
old := puppet.SystemConfigPath
|
||||
puppet.SystemConfigPath = filepath.Join(dir, "etc-config.yaml")
|
||||
t.Cleanup(func() { puppet.SystemConfigPath = old })
|
||||
|
||||
err := execute([]string{"host1"})
|
||||
if err == nil || !strings.Contains(err.Error(), "puppetboard_url") {
|
||||
t.Fatalf("expected missing puppetboard_url error, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user