Refactored GetDevices and test to use release_version
parent
10e19a1292
commit
ae0d16b3de
|
@ -6,7 +6,6 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
)
|
||||
|
@ -68,7 +67,7 @@ type Partition struct {
|
|||
}
|
||||
|
||||
// GetDevices : Returns a list of all available sotrage devices in structs filled with information
|
||||
func GetDevices() []Device {
|
||||
func GetDevices(release_version string) []Device {
|
||||
|
||||
var devices []Device
|
||||
|
||||
|
@ -83,11 +82,11 @@ func GetDevices() []Device {
|
|||
|
||||
mainDiskID := "sda"
|
||||
|
||||
if diagnostics.Version == "dev" {
|
||||
if release_version == "dev" {
|
||||
mainDiskID = "sda"
|
||||
} else if diagnostics.Version == "prod" {
|
||||
} else if release_version == "prod" {
|
||||
mainDiskID = "mmcblk0"
|
||||
} else if diagnostics.Version == "cloud" {
|
||||
} else if release_version == "cloud" {
|
||||
mainDiskID = "vda"
|
||||
}
|
||||
|
||||
|
|
|
@ -7,33 +7,37 @@ import (
|
|||
)
|
||||
|
||||
func TestGetDevices(t *testing.T) {
|
||||
result := GetDevices()
|
||||
|
||||
if len(result) == 0 {
|
||||
t.Log("Testing with release version dev")
|
||||
assertGetDevices(GetDevices("dev"), t)
|
||||
t.Log("Testing with release version prod")
|
||||
assertGetDevices(GetDevices("prod"), t)
|
||||
t.Log("Testing with release version cloud")
|
||||
assertGetDevices(GetDevices("cloud"), t)
|
||||
|
||||
}
|
||||
|
||||
func assertGetDevices(devices []Device, t *testing.T) {
|
||||
|
||||
if len(devices) == 0 {
|
||||
t.Log("Expecting at least 1 block device, 0 elements found in slice")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
foundMainDevice := false
|
||||
foundDevice := false
|
||||
|
||||
t.Log("Looking for a mmcblk0 or sda device")
|
||||
for _, device := range result {
|
||||
t.Log("Looking for a mmcblk0, sda or dva device")
|
||||
for _, device := range devices {
|
||||
|
||||
if device.MainDevice {
|
||||
t.Log("Found target main device", device.ID)
|
||||
foundMainDevice = true
|
||||
}
|
||||
|
||||
if device.ID == "mmcblk0" || device.ID == "sda" {
|
||||
if device.ID == "mmcblk0" || device.ID == "sda" || device.ID == "vda" {
|
||||
t.Log("Found target device", device.ID)
|
||||
foundDevice = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if !foundDevice || !foundMainDevice {
|
||||
t.Log("Expected to find device mmcblk0 but did not. Devices:", result)
|
||||
if !foundDevice {
|
||||
t.Log("Expected to find device mmcblk0, sda or dva but did not. Devices:", devices)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -472,7 +472,7 @@ func taskGetSystemUptime() string {
|
|||
func taskGetStorageDevices() string {
|
||||
fmt.Println("Executing taskGetStorageDevices")
|
||||
|
||||
devices := storage.GetDevices()
|
||||
devices := storage.GetDevices(diagnostics.Version)
|
||||
devicesJSON, _ := json.Marshal(devices)
|
||||
|
||||
db, err := sql.Open("sqlite3", utils.GetSQLiteDbConnectionDetails())
|
||||
|
|
Loading…
Reference in New Issue