Skip to content

Commit 27f1cdd

Browse files
committed
fix test import cycle
1 parent 5712edc commit 27f1cdd

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

.github/workflows/test-macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ main, develop]
3+
branches: [ main, develop,feature/test-goreleaser]
44
pull_request:
55
branches: [ main]
66
name: Test-MacOs

.github/workflows/test-ssh.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ main, develop]
3+
branches: [ main, develop,feature/test-goreleaser]
44
pull_request:
55
branches: [ main]
66
name: Test-Linux
@@ -17,10 +17,11 @@ jobs:
1717
- name: Setup SSH server and config
1818
# run docker ssh container for ssh tests
1919
run: |
20-
make prep-ci-ssh
2120
make dependencies
2221
make build-frontend
22+
make prep-ci-ssh
2323
- name: Test
2424
run: |
25-
go mod tidy
25+
go mod tidy
26+
ls /home/runner/work/saido/saido/ssh-key/ci/
2627
go test -v ./...

.github/workflows/test-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: [ main, develop]
3+
branches: [ main, develop,feature/test-goreleaser]
44
pull_request:
55
branches: [ main]
66
name: Test-Windows

client/controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (hosts *HostsController) getDriver(address string) *driver.Driver {
4747
func (hosts *HostsController) resetDriver(host config.Host) {
4848
hosts.mu.Lock()
4949
defer hosts.mu.Unlock()
50-
hostDriver := host.Connection.ToDriver()
50+
hostDriver := driver.ToDriver(*host.Connection)
5151
hosts.Drivers[host.Address] = &hostDriver
5252
}
5353

@@ -175,6 +175,12 @@ func (hosts *HostsController) ServeHTTP(w http.ResponseWriter, req *http.Request
175175
// NewHostsController : initialze host controller with config file
176176
func NewHostsController(cfg *config.Config) *HostsController {
177177
dashboardInfo := config.GetDashboardInfoConfig(cfg)
178+
for metric, _ := range dashboardInfo.Metrics {
179+
if !inspector.Valid(metric) {
180+
log.Fatalf("%s is not a valid metric", metric)
181+
}
182+
}
183+
178184
hosts := &HostsController{
179185
Info: dashboardInfo,
180186
Drivers: make(map[string]*driver.Driver),

config/config.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"io/ioutil"
66

7-
"github.com/bisohns/saido/driver"
8-
"github.com/bisohns/saido/inspector"
7+
// "github.com/bisohns/saido/driver"
8+
99
"github.com/mitchellh/mapstructure"
1010
log "github.com/sirupsen/logrus"
1111

@@ -49,23 +49,6 @@ type Connection struct {
4949
Host string
5050
}
5151

52-
func (conn *Connection) ToDriver() driver.Driver {
53-
switch conn.Type {
54-
case "ssh":
55-
return &driver.SSH{
56-
User: conn.Username,
57-
Host: conn.Host,
58-
Port: int(conn.Port),
59-
KeyFile: conn.PrivateKeyPath,
60-
KeyPass: conn.PrivateKeyPassPhrase,
61-
Password: conn.Password,
62-
CheckKnownHosts: false,
63-
}
64-
default:
65-
return &driver.Local{}
66-
}
67-
}
68-
6952
type Host struct {
7053
Address string
7154
Alias string
@@ -104,11 +87,8 @@ func GetDashboardInfoConfig(config *Config) *DashboardInfo {
10487
dashboardInfo.Hosts = parseConfig("root", "", config.Hosts, &Connection{})
10588
for metric, customCommand := range config.Metrics {
10689
metric := fmt.Sprintf("%v", metric)
107-
if inspector.Valid(metric) {
108-
metrics[metric] = fmt.Sprintf("%v", customCommand)
109-
} else {
110-
log.Fatalf("Found invalid metric %v", metric)
111-
}
90+
metrics[metric] = fmt.Sprintf("%v", customCommand)
91+
11292
}
11393
dashboardInfo.Metrics = metrics
11494
for _, host := range dashboardInfo.Hosts {

driver/driver.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package driver
22

3+
import "github.com/bisohns/saido/config"
4+
35
// SystemInfo gives more insight into system details
46
type SystemDetails struct {
57
IsWindows bool
@@ -26,3 +28,20 @@ type Driver interface {
2628
// shows the driver details, not sure if we should be showing OS name
2729
GetDetails() SystemDetails
2830
}
31+
32+
func ToDriver(conn config.Connection) Driver {
33+
switch conn.Type {
34+
case "ssh":
35+
return &SSH{
36+
User: conn.Username,
37+
Host: conn.Host,
38+
Port: int(conn.Port),
39+
KeyFile: conn.PrivateKeyPath,
40+
KeyPass: conn.PrivateKeyPassPhrase,
41+
Password: conn.Password,
42+
CheckKnownHosts: false,
43+
}
44+
default:
45+
return &Local{}
46+
}
47+
}

0 commit comments

Comments
 (0)