mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-12 02:00:18 +01:00
refactor: split into packages and add tests
This commit is contained in:
parent
fd58344ca7
commit
11117e0c0e
28 changed files with 2736 additions and 636 deletions
64
internal/types/types.go
Normal file
64
internal/types/types.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
type TestType string
|
||||
|
||||
const (
|
||||
TestTypeScript TestType = "script"
|
||||
TestTypeUnit TestType = "unit"
|
||||
TestTypeSnapshot TestType = "snapshot"
|
||||
)
|
||||
|
||||
type SuiteSpec struct {
|
||||
Name string `json:"name"`
|
||||
Tests []TestSpec `json:"tests"`
|
||||
}
|
||||
|
||||
type TestSpec struct {
|
||||
Type TestType `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Expected any `json:"expected,omitempty"`
|
||||
Actual any `json:"actual,omitempty"`
|
||||
ActualDrv string `json:"actualDrv,omitempty"`
|
||||
Script string `json:"script,omitempty"`
|
||||
Pos string `json:"pos,omitempty"`
|
||||
|
||||
Suite string
|
||||
}
|
||||
|
||||
type TestStatus int
|
||||
|
||||
const (
|
||||
StatusSuccess TestStatus = iota
|
||||
StatusFailure
|
||||
StatusError
|
||||
StatusSkipped
|
||||
)
|
||||
|
||||
func (ts TestStatus) String() string {
|
||||
switch ts {
|
||||
case StatusSuccess:
|
||||
return "SUCCESS"
|
||||
case StatusFailure:
|
||||
return "FAILURE"
|
||||
case StatusError:
|
||||
return "ERROR"
|
||||
case StatusSkipped:
|
||||
return "SKIPPED"
|
||||
default:
|
||||
return "UNKNOWN"
|
||||
}
|
||||
}
|
||||
|
||||
type TestResult struct {
|
||||
Spec TestSpec
|
||||
Status TestStatus
|
||||
Duration time.Duration
|
||||
ErrorMessage string
|
||||
Expected string
|
||||
Actual string
|
||||
}
|
||||
|
||||
type Results map[string][]TestResult
|
||||
24
internal/types/types_test.go
Normal file
24
internal/types/types_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package types
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTestStatus_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
status TestStatus
|
||||
want string
|
||||
}{
|
||||
{"Success", StatusSuccess, "SUCCESS"},
|
||||
{"Failure", StatusFailure, "FAILURE"},
|
||||
{"Error", StatusError, "ERROR"},
|
||||
{"Skipped", StatusSkipped, "SKIPPED"},
|
||||
{"Unknown", TestStatus(99), "UNKNOWN"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.status.String(); got != tt.want {
|
||||
t.Errorf("TestStatus.String() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue