mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 05:41:43 +02:00
Refactored GetDevices and test to use release_version
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user