Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skeleton structs #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"golangci",
"goreleaser",
"libc",
"wagoid"
"wagoid",
"ipmitool"
],
"ignoreWords": [],
"version": "0.2"
Expand Down
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading