feat: add spec definition api with versioning
This commit is contained in:
@ -50,7 +50,7 @@ var agentRepositoryTestCases = []agentRepositoryTestCase{
|
||||
var unexistantAgentID datastore.AgentID = 9999
|
||||
var specData map[string]any
|
||||
|
||||
agent, err := repo.UpdateSpec(ctx, unexistantAgentID, string(spec.Name), 0, specData)
|
||||
agent, err := repo.UpdateSpec(ctx, unexistantAgentID, spec.Name, spec.Version, 0, specData)
|
||||
if err == nil {
|
||||
return errors.New("error should not be nil")
|
||||
}
|
||||
@ -71,7 +71,7 @@ var agentRepositoryTestCases = []agentRepositoryTestCase{
|
||||
Run: func(ctx context.Context, repo datastore.AgentRepository) error {
|
||||
var unexistantAgentID datastore.AgentID = 9999
|
||||
|
||||
err := repo.DeleteSpec(ctx, unexistantAgentID, string(spec.Name))
|
||||
err := repo.DeleteSpec(ctx, unexistantAgentID, spec.Name, spec.Version)
|
||||
if err == nil {
|
||||
return errors.New("error should not be nil")
|
||||
}
|
||||
|
14
internal/datastore/testsuite/spec_definition_repository.go
Normal file
14
internal/datastore/testsuite/spec_definition_repository.go
Normal file
@ -0,0 +1,14 @@
|
||||
package testsuite
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
)
|
||||
|
||||
func TestSpecDefinitionRepository(t *testing.T, repo datastore.SpecDefinitionRepository) {
|
||||
t.Run("Cases", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
runSpecDefinitionRepositoryTests(t, repo)
|
||||
})
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package testsuite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type specDefinitionRepositoryTestCase struct {
|
||||
Name string
|
||||
Skip bool
|
||||
Run func(ctx context.Context, repo datastore.SpecDefinitionRepository) error
|
||||
}
|
||||
|
||||
var specDefinitionRepositoryTestCases = []specDefinitionRepositoryTestCase{
|
||||
{
|
||||
Name: "Create a spec definition",
|
||||
Run: func(ctx context.Context, repo datastore.SpecDefinitionRepository) error {
|
||||
schema := []byte("{}")
|
||||
name := "net.example.foo"
|
||||
version := "0.0.0"
|
||||
|
||||
specDef, err := repo.Upsert(ctx, name, version, schema)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if specDef.CreatedAt.IsZero() {
|
||||
return errors.Errorf("specDef.CreatedAt should not be zero time")
|
||||
}
|
||||
|
||||
if specDef.UpdatedAt.IsZero() {
|
||||
return errors.Errorf("specDef.UpdatedAt should not be zero time")
|
||||
}
|
||||
|
||||
if e, g := name, specDef.Name; e != g {
|
||||
return errors.Errorf("specDef.Name: expected '%v', got '%v'", e, g)
|
||||
}
|
||||
|
||||
if e, g := version, specDef.Version; e != g {
|
||||
return errors.Errorf("specDef.Name: expected '%v', got '%v'", e, g)
|
||||
}
|
||||
|
||||
if e, g := schema, specDef.Schema; !reflect.DeepEqual(e, g) {
|
||||
return errors.Errorf("specDef.Schema: expected '%v', got '%v'", e, g)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func runSpecDefinitionRepositoryTests(t *testing.T, repo datastore.SpecDefinitionRepository) {
|
||||
for _, tc := range specDefinitionRepositoryTestCases {
|
||||
func(tc specDefinitionRepositoryTestCase) {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if tc.Skip {
|
||||
t.SkipNow()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
if err := tc.Run(ctx, repo); err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
}
|
||||
})
|
||||
}(tc)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user