generator: stamp vectors with generation data; omitempty. (#237)
This commit is contained in:
parent
b2adc12287
commit
955b445723
@ -41,6 +41,14 @@ type Generator struct {
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// genData is the generation data to stamp into vectors.
|
||||
// TODO in the future this should contain the commit of this tool and
|
||||
// the builder api.
|
||||
var genData = schema.GenerationData{
|
||||
Source: "script",
|
||||
Version: "v0",
|
||||
}
|
||||
|
||||
type MessageVectorGenItem struct {
|
||||
Metadata *schema.Metadata
|
||||
Func func(*Builder)
|
||||
@ -100,7 +108,7 @@ func (g *Generator) MessageVectorGroup(group string, vectors ...*MessageVectorGe
|
||||
w = os.Stdout
|
||||
} else {
|
||||
file := filepath.Join(g.OutputPath, fmt.Sprintf("%s--%s.json", group, item.Metadata.ID))
|
||||
out, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE, 0644)
|
||||
out, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
log.Printf("failed to write to file %s: %s", file, err)
|
||||
return
|
||||
@ -122,6 +130,9 @@ func (g *Generator) MessageVectorGroup(group string, vectors ...*MessageVectorGe
|
||||
func (g *Generator) generateOne(w io.Writer, b *MessageVectorGenItem, indent bool) {
|
||||
log.Printf("generating test vector: %s", b.Metadata.ID)
|
||||
|
||||
// stamp with our generation data.
|
||||
b.Metadata.Gen = genData
|
||||
|
||||
vector := MessageVector(b.Metadata)
|
||||
|
||||
// TODO: currently if an assertion fails, we call os.Exit(1), which
|
||||
|
@ -30,16 +30,16 @@ type Selector string
|
||||
// Metadata provides information on the generation of this test case
|
||||
type Metadata struct {
|
||||
ID string `json:"id"`
|
||||
Version string `json:"version"`
|
||||
Desc string `json:"description"`
|
||||
Comment string `json:"comment"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Desc string `json:"description,omitempty"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
Gen GenerationData `json:"gen"`
|
||||
}
|
||||
|
||||
// GenerationData tags the source of this test case
|
||||
type GenerationData struct {
|
||||
Source string `json:"source"`
|
||||
Version string `json:"version"`
|
||||
Source string `json:"source,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
// StateTree represents a state tree within preconditions and postconditions.
|
||||
@ -92,7 +92,7 @@ func (beb *Base64EncodedBytes) UnmarshalJSON(v []byte) error {
|
||||
// TestVector is a single test case
|
||||
type TestVector struct {
|
||||
Class `json:"class"`
|
||||
Selector `json:"selector"`
|
||||
Selector `json:"selector,omitempty"`
|
||||
Meta *Metadata `json:"_meta"`
|
||||
|
||||
// CAR binary data to be loaded into the test environment, usually a CAR
|
||||
|
Loading…
Reference in New Issue
Block a user