From 27f1cddd33565764b4229ae8c84767a6936f8f71 Mon Sep 17 00:00:00 2001 From: Daniel Eje Date: Thu, 17 Nov 2022 11:36:55 +0100 Subject: [PATCH] fix test import cycle --- .github/workflows/test-macos.yml | 2 +- .github/workflows/test-ssh.yml | 7 ++++--- .github/workflows/test-windows.yml | 2 +- client/controller.go | 8 +++++++- config/config.go | 28 ++++------------------------ driver/driver.go | 19 +++++++++++++++++++ 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index 3cc6e59..a0d6931 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -1,6 +1,6 @@ on: push: - branches: [ main, develop] + branches: [ main, develop,feature/test-goreleaser] pull_request: branches: [ main] name: Test-MacOs diff --git a/.github/workflows/test-ssh.yml b/.github/workflows/test-ssh.yml index 2590a37..f14e435 100644 --- a/.github/workflows/test-ssh.yml +++ b/.github/workflows/test-ssh.yml @@ -1,6 +1,6 @@ on: push: - branches: [ main, develop] + branches: [ main, develop,feature/test-goreleaser] pull_request: branches: [ main] name: Test-Linux @@ -17,10 +17,11 @@ jobs: - name: Setup SSH server and config # run docker ssh container for ssh tests run: | - make prep-ci-ssh make dependencies make build-frontend + make prep-ci-ssh - name: Test run: | - go mod tidy + go mod tidy + ls /home/runner/work/saido/saido/ssh-key/ci/ go test -v ./... diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index ec17739..7b9adb0 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -1,6 +1,6 @@ on: push: - branches: [ main, develop] + branches: [ main, develop,feature/test-goreleaser] pull_request: branches: [ main] name: Test-Windows diff --git a/client/controller.go b/client/controller.go index 83f687b..150dc08 100644 --- a/client/controller.go +++ b/client/controller.go @@ -47,7 +47,7 @@ func (hosts *HostsController) getDriver(address string) *driver.Driver { func (hosts *HostsController) resetDriver(host config.Host) { hosts.mu.Lock() defer hosts.mu.Unlock() - hostDriver := host.Connection.ToDriver() + hostDriver := driver.ToDriver(*host.Connection) hosts.Drivers[host.Address] = &hostDriver } @@ -175,6 +175,12 @@ func (hosts *HostsController) ServeHTTP(w http.ResponseWriter, req *http.Request // NewHostsController : initialze host controller with config file func NewHostsController(cfg *config.Config) *HostsController { dashboardInfo := config.GetDashboardInfoConfig(cfg) + for metric, _ := range dashboardInfo.Metrics { + if !inspector.Valid(metric) { + log.Fatalf("%s is not a valid metric", metric) + } + } + hosts := &HostsController{ Info: dashboardInfo, Drivers: make(map[string]*driver.Driver), diff --git a/config/config.go b/config/config.go index 62d2f49..7f2b8ca 100644 --- a/config/config.go +++ b/config/config.go @@ -4,8 +4,8 @@ import ( "fmt" "io/ioutil" - "github.com/bisohns/saido/driver" - "github.com/bisohns/saido/inspector" + // "github.com/bisohns/saido/driver" + "github.com/mitchellh/mapstructure" log "github.com/sirupsen/logrus" @@ -49,23 +49,6 @@ type Connection struct { Host string } -func (conn *Connection) ToDriver() driver.Driver { - switch conn.Type { - case "ssh": - return &driver.SSH{ - User: conn.Username, - Host: conn.Host, - Port: int(conn.Port), - KeyFile: conn.PrivateKeyPath, - KeyPass: conn.PrivateKeyPassPhrase, - Password: conn.Password, - CheckKnownHosts: false, - } - default: - return &driver.Local{} - } -} - type Host struct { Address string Alias string @@ -104,11 +87,8 @@ func GetDashboardInfoConfig(config *Config) *DashboardInfo { dashboardInfo.Hosts = parseConfig("root", "", config.Hosts, &Connection{}) for metric, customCommand := range config.Metrics { metric := fmt.Sprintf("%v", metric) - if inspector.Valid(metric) { - metrics[metric] = fmt.Sprintf("%v", customCommand) - } else { - log.Fatalf("Found invalid metric %v", metric) - } + metrics[metric] = fmt.Sprintf("%v", customCommand) + } dashboardInfo.Metrics = metrics for _, host := range dashboardInfo.Hosts { diff --git a/driver/driver.go b/driver/driver.go index bef464b..7dfa27d 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -1,5 +1,7 @@ package driver +import "github.com/bisohns/saido/config" + // SystemInfo gives more insight into system details type SystemDetails struct { IsWindows bool @@ -26,3 +28,20 @@ type Driver interface { // shows the driver details, not sure if we should be showing OS name GetDetails() SystemDetails } + +func ToDriver(conn config.Connection) Driver { + switch conn.Type { + case "ssh": + return &SSH{ + User: conn.Username, + Host: conn.Host, + Port: int(conn.Port), + KeyFile: conn.PrivateKeyPath, + KeyPass: conn.PrivateKeyPassPhrase, + Password: conn.Password, + CheckKnownHosts: false, + } + default: + return &Local{} + } +}