feat: add spec definition api with versioning
This commit is contained in:
@ -11,7 +11,7 @@ import (
|
||||
var schema []byte
|
||||
|
||||
func init() {
|
||||
if err := spec.Register(NameUCI, schema); err != nil {
|
||||
if err := spec.Register(string(Name), Version, schema); err != nil {
|
||||
panic(errors.WithStack(err))
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
||||
"$id": "https://uci.emissary.cadoles.com/spec.json",
|
||||
"title": "UCISpec",
|
||||
"description": "Emissary 'UCI' specification",
|
||||
@ -15,7 +15,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["packages"],
|
||||
"required": [
|
||||
"packages"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"postImportCommands": {
|
||||
@ -33,12 +35,18 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["command", "args"],
|
||||
"required": [
|
||||
"command",
|
||||
"args"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["config", "postImportCommands"],
|
||||
"required": [
|
||||
"config",
|
||||
"postImportCommands"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"$defs": {
|
||||
"package": {
|
||||
@ -54,7 +62,10 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["name", "configs"],
|
||||
"required": [
|
||||
"name",
|
||||
"configs"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"config": {
|
||||
@ -74,11 +85,15 @@
|
||||
"$ref": "#/$defs/option"
|
||||
}
|
||||
},
|
||||
{ "type": "null" }
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": ["name"],
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"option": {
|
||||
@ -86,7 +101,10 @@
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": ["list", "option"]
|
||||
"enum": [
|
||||
"list",
|
||||
"option"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
@ -95,7 +113,11 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["type", "name", "value"],
|
||||
"required": [
|
||||
"type",
|
||||
"name",
|
||||
"value"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import (
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/spec"
|
||||
)
|
||||
|
||||
const NameUCI spec.Name = "uci.emissary.cadoles.com"
|
||||
const (
|
||||
Name string = "uci.emissary.cadoles.com"
|
||||
Version string = "0.0.0"
|
||||
)
|
||||
|
||||
type Spec struct {
|
||||
Revision int `json:"revision"`
|
||||
@ -18,8 +21,12 @@ type UCIPostImportCommand struct {
|
||||
Args []string `json:"args"`
|
||||
}
|
||||
|
||||
func (s *Spec) SpecName() spec.Name {
|
||||
return NameUCI
|
||||
func (s *Spec) SpecDefinitionName() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
func (s *Spec) SpecDefinitionVersion() string {
|
||||
return Version
|
||||
}
|
||||
|
||||
func (s *Spec) SpecRevision() int {
|
||||
|
@ -3,9 +3,10 @@ package uci
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore/memory"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/spec"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -32,17 +33,21 @@ var validatorTestCases = []validatorTestCase{
|
||||
func TestValidator(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
validator := spec.NewValidator()
|
||||
if err := validator.Register(NameUCI, schema); err != nil {
|
||||
ctx := context.Background()
|
||||
|
||||
repo := memory.NewSpecDefinitionRepository()
|
||||
if _, err := repo.Upsert(ctx, Name, Version, schema); err != nil {
|
||||
t.Fatalf("+%v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
validator := spec.NewValidator(repo)
|
||||
|
||||
for _, tc := range validatorTestCases {
|
||||
func(tc validatorTestCase) {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
rawSpec, err := ioutil.ReadFile(tc.Source)
|
||||
rawSpec, err := os.ReadFile(tc.Source)
|
||||
if err != nil {
|
||||
t.Fatalf("+%v", errors.WithStack(err))
|
||||
}
|
||||
|
Reference in New Issue
Block a user