Skip to content

Commit

Permalink
api: add Integration test cases (#43)
Browse files Browse the repository at this point in the history
* return the list of objects only

* return the updated object as response instead of word updated

* improves error handling

* adds test cases

* restructure the tests code

* fix: correct go version and run tests in dockerfile (#48)

* fix: correct go version in dockerfile

* ci: run build and push image on PRs

* run go test command

* readme: show the build badge instead of lint

* tests build

* tests build

---------

Co-authored-by: Vishnu Bharathi <[email protected]>
  • Loading branch information
ashwiniag and scriptnull authored Dec 21, 2024
1 parent 376f71d commit 477ca73
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 36 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ FROM golang:1.23-alpine AS builder
SHELL ["/bin/ash", "-o", "pipefail", "-c"]

# Install build dependencies
RUN apk add --no-cache git bash
RUN apk add --no-cache git bash gcc sqlite-dev musl-dev libc-dev

# Set CGO_ENABLED for sqlite3 compatibility
# ENV CGO_ENABLED=1
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"

# Set the working directory
WORKDIR /app
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,36 @@ go 1.23.0
toolchain go1.23.1

require (
entgo.io/ent v0.14.1
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.16
github.com/robfig/cron/v3 v3.0.1
github.com/scriptnull/jsonseal v0.3.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.10.0
github.com/swaggest/openapi-go v0.2.54
github.com/swaggest/rest v0.2.68
github.com/swaggest/swgui v1.8.2
github.com/swaggest/usecase v1.3.1
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
gopkg.in/yaml.v2 v2.4.0
)

require (
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect
entgo.io/ent v0.14.1 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-chi/chi/v5 v5.1.0 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/santhosh-tekuri/jsonschema/v3 v3.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -41,9 +43,8 @@ require (
github.com/swaggest/refl v1.3.0 // indirect
github.com/vearutop/statigz v1.4.0 // indirect
github.com/zclconf/go-cty v1.8.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.26.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrl
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU=
entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=
entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
Expand All @@ -28,13 +30,15 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc=
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
Expand All @@ -49,14 +53,14 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -78,8 +82,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ=
github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
github.com/swaggest/form/v5 v5.1.1 h1:ct6/rOQBGrqWUQ0FUv3vW5sHvTUb31AwTUWj947N6cY=
Expand Down Expand Up @@ -107,23 +111,19 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf
github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA=
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
17 changes: 10 additions & 7 deletions internal/restapi/v1/integrations/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integrations
import (
"context"
"errors"
"fmt"
"github.com/google/uuid"
"github.com/shinobistack/gokakashi/ent"
"github.com/swaggest/usecase/status"
Expand Down Expand Up @@ -31,9 +32,13 @@ func GetIntegration(client *ent.Client) func(ctx context.Context, req GetIntegra
return status.Wrap(errors.New("invalid UUID format"), status.InvalidArgument)
}

// Fetch integration by ID
integration, err := client.Integrations.Get(ctx, uid)
if err != nil {
return status.Wrap(errors.New("integration not found"), status.NotFound)
if ent.IsNotFound(err) {
return status.Wrap(errors.New("integration not found"), status.NotFound)
}
return status.Wrap(fmt.Errorf("unexpected error: %v", err), status.Internal)
}

res.ID = integration.ID.String()
Expand All @@ -46,24 +51,22 @@ func GetIntegration(client *ent.Client) func(ctx context.Context, req GetIntegra
}
}

func ListIntegrations(client *ent.Client) func(ctx context.Context, req struct{}, res *ListIntegrationResponse) error {
return func(ctx context.Context, req struct{}, res *ListIntegrationResponse) error {
func ListIntegrations(client *ent.Client) func(ctx context.Context, req struct{}, res *[]GetIntegrationResponse) error {
return func(ctx context.Context, req struct{}, res *[]GetIntegrationResponse) error {
integrations, err := client.Integrations.Query().All(ctx)
if err != nil {
return status.Wrap(errors.New("failed to fetch integrations"), status.Internal)
}

responses := make([]GetIntegrationResponse, len(integrations))
*res = make([]GetIntegrationResponse, len(integrations))
for i, integration := range integrations {
responses[i] = GetIntegrationResponse{
(*res)[i] = GetIntegrationResponse{
ID: integration.ID.String(),
Name: integration.Name,
Type: integration.Type,
Config: integration.Config,
}
}

res.Integrations = responses
return nil
}
}
98 changes: 98 additions & 0 deletions internal/restapi/v1/integrations/get_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package integrations_test

import (
"context"
"github.com/google/uuid"
_ "github.com/mattn/go-sqlite3"
"github.com/shinobistack/gokakashi/ent/enttest"
"github.com/shinobistack/gokakashi/internal/restapi/v1/integrations"
"github.com/stretchr/testify/assert"
"testing"
)

func TestGetIntegration(t *testing.T) {
// client := enttest.Open(t, "postgres", "host=localhost port=5432 user=postgres password=secret dbname=testdb sslmode=disable")
// This requires a running DB with pre-configured testdb

// sqlite3 lightweight, file based db faster to test
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
defer client.Close()

// Seed the DB
id := uuid.New()
_, err := client.Integrations.Create().
SetID(id).
SetName("Test Integration").
SetType("linear").
SetConfig(map[string]interface{}{"Key": "value"}).
Save(context.Background())
assert.NoError(t, err)

// Test case: Valid ID
req := integrations.GetIntegrationRequests{ID: id.String()}
res := &integrations.GetIntegrationResponse{}
handler := integrations.GetIntegration(client)
err = handler(context.Background(), req, res)

assert.NoError(t, err)
assert.Equal(t, "Test Integration", res.Name)
assert.Equal(t, "linear", res.Type)

// Test case: Invalid UUID
req = integrations.GetIntegrationRequests{ID: "invalid-uuid"}
err = handler(context.Background(), req, res)
assert.Error(t, err)

// Test case: Non-existent ID
req = integrations.GetIntegrationRequests{ID: uuid.New().String()}
err = handler(context.Background(), req, res)
assert.Error(t, err)

}

func TestListIntegrations(t *testing.T) {
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
defer client.Close()

// Seed the db
_, err := client.Integrations.Create().
SetName("Integration 1").
SetType("linear").
SetConfig(map[string]interface{}{"key": "value1"}).
Save(context.Background())
assert.NoError(t, err)

_, err = client.Integrations.Create().
SetName("Integration 2").
SetType("jira").
SetConfig(map[string]interface{}{"key": "value2"}).
Save(context.Background())
assert.NoError(t, err)

// Test case: List integrations
req := struct{}{}
var res []integrations.GetIntegrationResponse
handler := integrations.ListIntegrations(client)
err = handler(context.Background(), req, &res)

assert.NoError(t, err)
assert.Len(t, res, 2)
assert.Equal(t, "Integration 1", res[0].Name)
assert.Equal(t, "Integration 2", res[1].Name)
}

func TestListIntegrations_EmptyDB(t *testing.T) {
client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
defer client.Close()

// Prepare response
var res []integrations.GetIntegrationResponse

// Execute ListIntegrations handler
handler := integrations.ListIntegrations(client)
err := handler(context.Background(), struct{}{}, &res)

// Validate response
assert.NoError(t, err)
assert.Len(t, res, 0)
}
18 changes: 18 additions & 0 deletions internal/restapi/v1/integrations/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package integrations

import (
"context"
"errors"
"fmt"
"github.com/shinobistack/gokakashi/ent"
"github.com/shinobistack/gokakashi/ent/integrations"
"github.com/swaggest/usecase/status"
)

Expand All @@ -20,6 +22,22 @@ type CreateIntegrationResponse struct {

func CreateIntegration(client *ent.Client) func(ctx context.Context, req CreateIntegrationRequest, res *CreateIntegrationResponse) error {
return func(ctx context.Context, req CreateIntegrationRequest, res *CreateIntegrationResponse) error {
// Validate required fields
if req.Name == "" || req.Type == "" {
return status.Wrap(errors.New("missing required fields: name and/or type"), status.InvalidArgument)
}

// Check for duplicate name
exists, err := client.Integrations.Query().
Where(integrations.Name(req.Name)).
Exist(ctx)
if err != nil {
return status.Wrap(fmt.Errorf("failed to check for duplicate integration name: %v", err), status.Internal)
}
if exists {
return status.Wrap(errors.New("integration with the same name already exists"), status.AlreadyExists)
}

integration, err := client.Integrations.Create().
SetName(req.Name).
SetType(req.Type).
Expand Down
Loading

0 comments on commit 477ca73

Please sign in to comment.