Adjust + Test

This commit is contained in:
mr
2026-02-18 12:24:19 +01:00
parent 842e09f22f
commit fa5c3a3c60
45 changed files with 1166 additions and 1192 deletions

View File

@@ -12,6 +12,7 @@ import (
"cloud.o-forge.io/core/oc-lib/models/booking"
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
"cloud.o-forge.io/core/oc-lib/models/common"
"cloud.o-forge.io/core/oc-lib/models/common/models"
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
"cloud.o-forge.io/core/oc-lib/models/peer"
"cloud.o-forge.io/core/oc-lib/models/resources"
@@ -41,7 +42,9 @@ type Workflow struct {
Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"` // Graph UI & logic representation of the workflow
ScheduleActive bool `json:"schedule_active" bson:"schedule_active"` // ScheduleActive is a flag that indicates if the schedule is active, if not the workflow is not scheduled and no execution or booking will be set
// Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"` // Schedule is the schedule of the workflow
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow // AbstractWorkflow contains the basic fields of a workflow
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow // AbstractWorkflow contains the basic fields of a workflow
Env []models.Param `json:"env,omitempty" bson:"env,omitempty"`
Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"`
}
func (d *Workflow) GetAccessor(request *tools.APIRequest) utils.Accessor {
@@ -390,11 +393,13 @@ func (w *Workflow) GetPricedItem(
for _, item := range w.Graph.Items {
if f(item) {
dt, res := item.GetResource()
ord, err := res.ConvertToPricedResource(dt, &instance, &partnership, &buying, &strategy, &bookingMode, request)
if err != nil {
return list_datas, err
}
list_datas[res.GetID()] = ord
}
}
return list_datas, nil
@@ -445,6 +450,7 @@ func (ao *Workflow) VerifyAuth(callName string, request *tools.APIRequest) bool
return ao.AbstractObject.VerifyAuth(callName, request) || isAuthorized
}
// TODO : Check Booking... + Storage
/*
* CheckBooking is a function that checks the booking of the workflow on peers (even ourselves)
*/

View File

@@ -14,10 +14,10 @@ import (
)
type workflowMongoAccessor struct {
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
computeResourceAccessor utils.Accessor
collaborativeAreaAccessor utils.Accessor
workspaceAccessor utils.Accessor
utils.AbstractAccessor[*Workflow] // AbstractAccessor contains the basic fields of an accessor (model, caller)
computeResourceAccessor utils.Accessor
collaborativeAreaAccessor utils.Accessor
workspaceAccessor utils.Accessor
}
func NewAccessorHistory(request *tools.APIRequest) *workflowMongoAccessor {
@@ -34,7 +34,7 @@ func new(t tools.DataType, request *tools.APIRequest) *workflowMongoAccessor {
computeResourceAccessor: (&resources.ComputeResource{}).GetAccessor(request),
collaborativeAreaAccessor: (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(request),
workspaceAccessor: (&workspace.Workspace{}).GetAccessor(request),
AbstractAccessor: utils.AbstractAccessor{
AbstractAccessor: utils.AbstractAccessor[*Workflow]{
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
Request: request,
Type: t,
@@ -186,10 +186,6 @@ func (a *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
}, a)
}
func (a *workflowMongoAccessor) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
return utils.GenericLoadAll[*Workflow](func(d utils.DBObject) utils.ShallowDBObject { return &d.(*Workflow).AbstractObject }, isDraft, a)
}
func (a *workflowMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
return utils.GenericSearch[*Workflow](filters, search, (&Workflow{}).GetObjectFilters(search), func(d utils.DBObject) utils.ShallowDBObject { return a.verifyResource(d) }, isDraft, a)
}

View File

@@ -4,26 +4,35 @@ import (
"testing"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
"github.com/stretchr/testify/assert"
)
func TestStoreOneWorkflow(t *testing.T) {
w := Workflow{
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
}
wma := NewAccessor(nil)
id, _, _ := wma.StoreOne(&w)
assert.NotEmpty(t, id)
func TestNewWorkflowAccessor(t *testing.T) {
req := &tools.APIRequest{}
acc := NewAccessor(req)
assert.NotNil(t, acc)
}
func TestLoadOneWorkflow(t *testing.T) {
w := Workflow{
func TestWorkflow_StoreDraftDefault(t *testing.T) {
w := &Workflow{
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
}
wma := NewAccessor(nil)
new_w, _, _ := wma.StoreOne(&w)
assert.Equal(t, w, new_w)
w.StoreDraftDefault()
assert.False(t, w.IsDraft)
}
func TestWorkflow_VerifyAuth_NilRequest(t *testing.T) {
w := &Workflow{
AbstractObject: utils.AbstractObject{},
}
result := w.VerifyAuth("get", nil)
assert.False(t, result)
}
func TestWorkflow_VerifyAuth_AdminRequest(t *testing.T) {
w := &Workflow{}
req := &tools.APIRequest{Admin: true}
result := w.VerifyAuth("get", req)
assert.True(t, result)
}