Skip to content

Commit 62b1729

Browse files
committed
Restructure project, rename orchestrator to runner, and embed json test data
1 parent 66dc976 commit 62b1729

File tree

8 files changed

+54
-38
lines changed

8 files changed

+54
-38
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ The framework ensures that all language bindings (Go, Python, Rust, etc.) behave
1515

1616
```
1717
┌─────────────┐ ┌──────────────────┐
18-
Orchestrator│────────▶│ Handler Binary │
19-
│ (Go Test │ stdin │ (Go/Rust/etc) │
20-
Runner) │◀────────│ │
18+
Test Runner │────────▶│ Handler Binary │
19+
│ (Go CLI) │ stdin │ (Go/Rust/etc) │
20+
│◀────────│ │
2121
└─────────────┘ stdout └──────────────────┘
2222
│ │
2323
│ │
2424
▼ ▼
2525
┌─────────┐ ┌────────────────┐
2626
│ Test │ │ Binding API │
2727
│ Cases │ └────────────────┘
28-
│ (JSON) │
28+
│ (JSON) │
2929
└─────────┘
3030
```
3131

3232
**This repository contains:**
33-
1. [**Orchestrator**](./orchestrator): Spawns handler binary, sends test requests via stdin, validates responses from stdout
33+
1. [**Test Runner**](./cmd/runner/main.go): Spawns handler binary, sends test requests via stdin, validates responses from stdout
3434
2. [**Test Cases**](./testdata): JSON files defining requests and expected responses
3535

3636
**Handler binaries** are not hosted in this repository. They must be implemented separately and should:
37-
- Implement the JSON protocol for communication with the orchestrator
37+
- Implement the JSON protocol for communication with the test runner
3838
- Call the binding API to execute operations
3939
- Pin to a specific version/tag of this test repository
Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"io/fs"
67
"os"
7-
"path/filepath"
88
"strings"
9+
10+
"github.com/stringintech/kernel-bindings-tests/runner"
11+
"github.com/stringintech/kernel-bindings-tests/testdata"
912
)
1013

1114
func main() {
1215
handlerPath := flag.String("handler", "", "Path to handler binary")
13-
testDir := flag.String("testdir", "", "Directory containing test JSON files")
14-
testFile := flag.String("testfile", "", "Single test file to run")
1516
flag.Parse()
1617

1718
if *handlerPath == "" {
@@ -20,25 +21,13 @@ func main() {
2021
os.Exit(1)
2122
}
2223

23-
if *testDir == "" && *testFile == "" {
24-
fmt.Fprintf(os.Stderr, "Error: either -testdir or -testfile must be specified\n")
25-
flag.Usage()
24+
// Collect embedded test files
25+
testFiles, err := fs.Glob(testdata.FS, "*.json")
26+
if err != nil {
27+
fmt.Fprintf(os.Stderr, "Error finding test files: %v\n", err)
2628
os.Exit(1)
2729
}
2830

29-
// Collect test files
30-
var testFiles []string
31-
if *testFile != "" {
32-
testFiles = []string{*testFile}
33-
} else {
34-
files, err := filepath.Glob(filepath.Join(*testDir, "*.json"))
35-
if err != nil {
36-
fmt.Fprintf(os.Stderr, "Error finding test files: %v\n", err)
37-
os.Exit(1)
38-
}
39-
testFiles = files
40-
}
41-
4231
if len(testFiles) == 0 {
4332
fmt.Fprintf(os.Stderr, "No test files found\n")
4433
os.Exit(1)
@@ -50,25 +39,25 @@ func main() {
5039
totalTests := 0
5140

5241
for _, testFile := range testFiles {
53-
fmt.Printf("\n=== Running test suite: %s ===\n", filepath.Base(testFile))
42+
fmt.Printf("\n=== Running test suite: %s ===\n", testFile)
5443

55-
// Load test suite
56-
suite, err := LoadTestSuite(testFile)
44+
// Load test suite from embedded FS
45+
suite, err := runner.LoadTestSuiteFromFS(testdata.FS, testFile)
5746
if err != nil {
5847
fmt.Fprintf(os.Stderr, "Error loading test suite: %v\n", err)
5948
continue
6049
}
6150

6251
// Create test runner
63-
runner, err := NewTestRunner(*handlerPath)
52+
testRunner, err := runner.NewTestRunner(*handlerPath)
6453
if err != nil {
6554
fmt.Fprintf(os.Stderr, "Error creating test runner: %v\n", err)
6655
continue
6756
}
6857

6958
// Run suite
70-
result := runner.RunTestSuite(*suite)
71-
runner.Close()
59+
result := testRunner.RunTestSuite(*suite)
60+
testRunner.Close()
7261

7362
printResults(result)
7463

@@ -90,7 +79,7 @@ func main() {
9079
}
9180
}
9281

93-
func printResults(result TestResult) {
82+
func printResults(result runner.TestResult) {
9483
fmt.Printf("\nTest Suite: %s\n", result.SuiteName)
9584
fmt.Printf("Total: %d, Passed: %d, Failed: %d\n\n", result.TotalTests, result.PassedTests, result.FailedTests)
9685

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/stringintech/kernel-bindings-tests
2+
3+
go 1.23

orchestrator/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

orchestrator/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
package main
1+
package runner
22

33
import (
44
"bufio"
55
"bytes"
6+
"embed"
67
"encoding/json"
78
"fmt"
89
"io"
10+
"io/fs"
911
"os"
1012
"os/exec"
1113
"path/filepath"
@@ -261,3 +263,23 @@ func LoadTestSuite(filePath string) (*TestSuite, error) {
261263

262264
return &suite, nil
263265
}
266+
267+
// LoadTestSuiteFromFS loads a test suite from an embedded filesystem
268+
func LoadTestSuiteFromFS(fsys embed.FS, filePath string) (*TestSuite, error) {
269+
data, err := fs.ReadFile(fsys, filePath)
270+
if err != nil {
271+
return nil, fmt.Errorf("failed to read file: %w", err)
272+
}
273+
274+
var suite TestSuite
275+
if err := json.Unmarshal(data, &suite); err != nil {
276+
return nil, fmt.Errorf("failed to parse JSON: %w", err)
277+
}
278+
279+
// Set suite name from filename if not specified
280+
if suite.Name == "" {
281+
suite.Name = filepath.Base(filePath)
282+
}
283+
284+
return &suite, nil
285+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package runner
22

33
import (
44
"encoding/json"

testdata/testdata.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package testdata
2+
3+
import "embed"
4+
5+
//go:embed *.json
6+
var FS embed.FS

0 commit comments

Comments
 (0)