quorum/test_runner.go

36 lines
547 B
Go
Raw Normal View History

2014-01-01 06:49:38 -08:00
package main
import (
2014-01-11 06:27:08 -08:00
"encoding/json"
"fmt"
"testing"
2014-01-01 06:49:38 -08:00
)
type TestSource struct {
2014-01-11 06:27:08 -08:00
Inputs map[string]string
Expectation string
2014-01-01 06:49:38 -08:00
}
func NewTestSource(source string) *TestSource {
2014-01-11 06:27:08 -08:00
s := &TestSource{}
err := json.Unmarshal([]byte(source), s)
if err != nil {
fmt.Println(err)
}
2014-01-01 06:49:38 -08:00
2014-01-11 06:27:08 -08:00
return s
2014-01-01 06:49:38 -08:00
}
type TestRunner struct {
2014-01-11 06:27:08 -08:00
source *TestSource
2014-01-01 06:49:38 -08:00
}
func NewTestRunner(t *testing.T) *TestRunner {
2014-01-11 06:27:08 -08:00
return &TestRunner{}
2014-01-01 06:49:38 -08:00
}
func (runner *TestRunner) RunFromString(input string, Cb func(*TestSource)) {
2014-01-11 06:27:08 -08:00
source := NewTestSource(input)
Cb(source)
2014-01-01 06:49:38 -08:00
}