Storage Module Basis (#13)

* Added storage module, base structs, getDevices() func, taskGetStorageDevices (ticks every 30)

* GetDevices now returns a complete description w/ disk partitions

* Added InUse flag to Device, fixed logic bugs

* Added disk space usage for partitions in use by the system

* Cleanup

* Added UsageStat and UsageSplit filling for in use devices

* Changed value of lsblk block usage output to bytes

* Cleanup, small fixes

* Added ExecAndGetLines util func

* Added explicit detection of disk or part block type, ignoring non-suppoorted devices

* Added command line tool dependencies for the project in README file

* Added comment to func ExecAndGetLines

* Removed GetMySQLDbConnectionDetails()

* Added tests to utils module

* Fix invalid argument type for Exec family of tests

* Removed too much verbosity from utils.GetPath when no env file is available, added new argument (path) to Exec family of funcs

* Added new path argument to utils.Exec... test

* Fixed TestExec

* Added spaces trim to Exec result

* Trimming spaces and newlines from result of Exec

* Better visibility for test result log of TestExec

* Added ExampleExecAndStream test

* Added Example tests with failure status for ExecAndStream

* Added branch to test for valid key in GetPath

* Added missing t.Fail() statements in utils_test.go

* Added storage_test.go file, smoke test

* TestGetDevices
This commit is contained in:
Paulo Truta
2021-06-13 12:03:36 +02:00
committed by GitHub
parent 92ac9c2b03
commit 9339e6cf09
9 changed files with 483 additions and 46 deletions
+90
View File
@@ -7,6 +7,96 @@ import (
"time"
)
func TestExec(t *testing.T) {
testCommand := "echo"
testArguments := []string{"Hello World"}
result := Exec("/", testCommand, testArguments)
if result != "Hello World" {
t.Log("Expected 'Hello World' but got", "'"+result+"'")
t.Fail()
}
}
func ExampleExecAndStream() {
ExecAndStream("/", "echo", []string{"Hello"})
// Output:
// Hello
//
// out:
// Hello
//
// err:
}
func ExampleExecAndStreamExecutableNotFound() {
ExecAndStream("/", "testcommand", []string{"Hello"})
// Output:
// cmd.Run() failed with exec: "testcommand": executable file not found in $PATH
//
// out:
//
// err:
}
func ExampleExecAndStreamError() {
ExecAndStream("/", "man", []string{"Hello"})
// Output:
// cmd.Run() failed with exit status 16
//
// out:
//
// err:
// No manual entry for Hello
}
func TestExecAndGetLines(t *testing.T) {
testCommand := "echo"
testArguments := []string{"$'Line1\nLine2\nLine3'"}
var result []string
scanner := ExecAndGetLines("/", testCommand, testArguments)
for scanner.Scan() {
result = append(result, scanner.Text())
}
if len(result) != 3 {
t.Log("Expected 3 lines but got ", len(result))
t.Fail()
}
}
func TestDeleteEmptySlices(t *testing.T) {
testSlice := []string{"Line1", "", "Line3"}
resultSlice := DeleteEmptySlices(testSlice)
if (len(resultSlice)) != 2 {
t.Log("Expected 2 slices but got ", len(resultSlice))
t.Fail()
}
}
func TestGetPath(t *testing.T) {
invalidPathKey := "test"
result := GetPath(invalidPathKey)
if result != "" {
t.Log("Expected empty result but got ", result)
t.Fail()
}
validPathKey := "wsPath"
result = GetPath(validPathKey)
if result != "/home/system/components/ws/" {
t.Log("Expected /home/system/components/ws/ but got", result)
t.Fail()
}
}
func TestGetSQLiteFormattedDateTime(t *testing.T) {
datetime := time.Date(2021, time.Month(1), 01, 1, 30, 15, 0, time.UTC)
result := GetSQLiteFormattedDateTime(datetime)