Skip to content

Commit

Permalink
fix test import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
derhnyel committed Nov 25, 2022
1 parent 5712edc commit 27f1cdd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
push:
branches: [ main, develop]
branches: [ main, develop,feature/test-goreleaser]
pull_request:
branches: [ main]
name: Test-MacOs
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test-ssh.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
push:
branches: [ main, develop]
branches: [ main, develop,feature/test-goreleaser]
pull_request:
branches: [ main]
name: Test-Linux
Expand All @@ -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 ./...
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
push:
branches: [ main, develop]
branches: [ main, develop,feature/test-goreleaser]
pull_request:
branches: [ main]
name: Test-Windows
Expand Down
8 changes: 7 additions & 1 deletion client/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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),
Expand Down
28 changes: 4 additions & 24 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions driver/driver.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package driver

import "github.com/bisohns/saido/config"

// SystemInfo gives more insight into system details
type SystemDetails struct {
IsWindows bool
Expand All @@ -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{}
}
}

0 comments on commit 27f1cdd

Please sign in to comment.