Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ __debug_bin*
/pro_impl/
/go.work.x
/go.work
/go.work.sum
/go.work.sum
config.json
database.boltdb
admin
5 changes: 5 additions & 0 deletions api/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ func GetTaskDefinition(integration db.Integration, payload []byte, r *http.Reque

taskDefinition.IntegrationID = &integration.ID

// Initialize Params if nil to avoid panic when assigning extracted task parameters
if taskDefinition.Params == nil {
taskDefinition.Params = make(db.MapStringAnyField)
}

env := make(map[string]any)

if taskDefinition.Environment != "" {
Expand Down
14 changes: 14 additions & 0 deletions db/Store.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,22 @@ func (m *MapStringAnyField) Scan(value any) error {

switch v := value.(type) {
case []byte:
// Handle empty byte slices by initializing an empty map instead of nil.
// This prevents "unexpected end of JSON input" errors and provides a usable empty map
// for subsequent operations, which is more intuitive than nil for empty data.
if len(v) == 0 {
*m = make(MapStringAnyField)
return nil
}
return json.Unmarshal(v, m)
case string:
// Handle empty strings by initializing an empty map instead of nil.
// This prevents "unexpected end of JSON input" errors and provides a usable empty map
// for subsequent operations, which is more intuitive than nil for empty data.
if v == "" {
*m = make(MapStringAnyField)
return nil
}
return json.Unmarshal([]byte(v), m)
default:
return errors.New("unsupported type for MapStringAnyField")
Expand Down
41 changes: 41 additions & 0 deletions db/Store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestObjectToJSON(t *testing.T) {
Expand Down Expand Up @@ -31,3 +32,43 @@ func TestObjectToJSON3(t *testing.T) {
assert.NotNil(t, s)
assert.Equal(t, "{\"name\":\"test\",\"title\":\"Test\"}", *s)
}

func TestMapStringAnyField_ScanEmptyString(t *testing.T) {
var m MapStringAnyField

// Test empty string
err := m.Scan("")
require.NoError(t, err, "Scan empty string should not return error")
require.NotNil(t, m, "Scan empty string should initialize map, not set to nil")
assert.Equal(t, 0, len(m), "Scan empty string should initialize empty map")
}

func TestMapStringAnyField_ScanEmptyBytes(t *testing.T) {
var m MapStringAnyField

// Test empty byte slice
err := m.Scan([]byte{})
require.NoError(t, err, "Scan empty bytes should not return error")
require.NotNil(t, m, "Scan empty bytes should initialize map, not set to nil")
assert.Equal(t, 0, len(m), "Scan empty bytes should initialize empty map")
}

func TestMapStringAnyField_ScanNil(t *testing.T) {
var m MapStringAnyField

// Test nil value
err := m.Scan(nil)
require.NoError(t, err, "Scan nil should not return error")
assert.Nil(t, m, "Scan nil should set map to nil")
}

func TestMapStringAnyField_ScanValidJSON(t *testing.T) {
var m MapStringAnyField

// Test valid JSON string
err := m.Scan(`{"key": "value", "number": 42}`)
require.NoError(t, err, "Scan valid JSON should not return error")
require.NotNil(t, m, "Scan valid JSON should initialize map")
assert.Equal(t, "value", m["key"], "Expected key='value'")
assert.Equal(t, float64(42), m["number"], "Expected number=42")
}
30 changes: 30 additions & 0 deletions db/bolt/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ func (d *BoltDb) CreateIntegration(integration db.Integration) (db.Integration,

func (d *BoltDb) GetIntegrations(projectID int, params db.RetrieveQueryParams, includeTaskParams bool) (integrations []db.Integration, err error) {
err = d.getObjects(projectID, db.IntegrationProps, params, nil, &integrations)

if err != nil {
return integrations, err
}

if includeTaskParams {
for i := range integrations {
if integrations[i].TaskParamsID == nil {
continue
}

var taskParams db.TaskParams
err = d.getObject(projectID, db.TaskParamsProps, intObjectID(*integrations[i].TaskParamsID), &taskParams)
if err != nil {
return nil, err
}
integrations[i].TaskParams = &taskParams
}
}

return integrations, err
}

Expand All @@ -29,6 +49,16 @@ func (d *BoltDb) GetIntegration(projectID int, integrationID int) (integration d
if err != nil {
return
}

if integration.TaskParamsID != nil {
var taskParams db.TaskParams
err = d.getObject(projectID, db.TaskParamsProps, intObjectID(*integration.TaskParamsID), &taskParams)
if err != nil {
return
}

integration.TaskParams = &taskParams
}

return
}
Expand Down
Loading
Loading