Skip to content

Commit

Permalink
feat(test): add skeleton structs
Browse files Browse the repository at this point in the history
Define multiple structs to implement the tests.

Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
pointbazaar committed Sep 18, 2024
1 parent 8f5a68a commit 113b165
Showing 3 changed files with 76 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@
"golangci",
"goreleaser",
"libc",
"wagoid"
"wagoid",
"ipmitool"
],
"ignoreWords": [],
"version": "0.2"
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -5,10 +5,44 @@ package main

import (
"fmt"

"github.com/9elements/bmc-test-go/pkg/testcase"
)

const bmcTestGoVersion = "v0.0.0"

func printResult(name string, result testcase.Result) {
fmt.Printf("TEST [%s][%s]:", name, result.Name)

if result.Error != nil {
fmt.Printf(" Error: %v", result.Error)
} else {
fmt.Printf(" PASS")
}

fmt.Println()
}

func printResults(test testcase.Test) {
for _, r := range test.Results {
printResult(test.Name, r)
}
}

func main() {
fmt.Println(bmcTestGoVersion)

result1 := testcase.Result{Name: "step 1", Error: nil}
result2 := testcase.Result{Name: "step 2", Error: nil}

test := testcase.Test{
Name: "nop test",
Description: "showcasing how to use the structs",
Function: func(_ testcase.Config) []testcase.Result {
return []testcase.Result{result1, result2}
},
Results: []testcase.Result{result1, result2},
}

printResults(test)
}
40 changes: 40 additions & 0 deletions pkg/testcase/testcase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Package testcase implements the common structs used for defining
// testcases.
package testcase

// Config struct is used to pass arbitrary information into the tests
// such as IP address, expected FRU content, expected sensors
type Config struct {
Host string
Username string
Password string

// ... to be extended
}

// Result struct is used for returning test results from running a test
type Result struct {
// what was tested
Name string

// != nil in case something went wrong,
// this should contain a descriptive string for the logs.
// e.g. "while running command X, expected A but output was B'
Error error

// to store stdout/stderr from a command, if any
Output string
}

// Test struct is used to define a test which can return one or more results
type Test struct {
// e.g. "IPMI Sensor"
Name string

// e.g. "Testing the 'ipmitool sensor' output
Description string

Function func(tc Config) []Result

Results []Result
}

0 comments on commit 113b165

Please sign in to comment.