diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 40c830d..7e3150e 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -36,11 +36,11 @@ jobs: go test -race -coverprofile=coverage.txt -covermode=atomic ./cloudconnexa/... - name: Run e2e tests - if: ${{ vars.OVPN_HOST != '' }} + if: ${{ vars.CLOUDCONNEXA_BASE_URL != '' }} run: | go test -race ./e2e/... env: - OVPN_HOST: ${{ vars.OVPN_HOST }} + CLOUDCONNEXA_BASE_URL: ${{ vars.CLOUDCONNEXA_BASE_URL }} CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }} CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b8b5ada..1314604 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -58,6 +58,6 @@ jobs: - name: E2E Test run: make e2e env: - OVPN_HOST: ${{ vars.OVPN_HOST }} + CLOUDCONNEXA_BASE_URL: ${{ vars.CLOUDCONNEXA_BASE_URL }} CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }} CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }} diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 4193b47..c7fe203 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -27,7 +27,7 @@ jobs: with: args: ./... env: - OVPN_HOST: ${{ vars.OVPN_HOST }} + CLOUDCONNEXA_BASE_URL: ${{ vars.CLOUDCONNEXA_BASE_URL }} CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }} CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }} diff --git a/cloudconnexa/access_groups.go b/cloudconnexa/access_groups.go index d2ed0f7..569f2fd 100644 --- a/cloudconnexa/access_groups.go +++ b/cloudconnexa/access_groups.go @@ -6,6 +6,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -76,10 +77,9 @@ func (c *AccessGroupsService) GetAccessGroupsByPage(page int, size int) (AccessG func (c *AccessGroupsService) List() ([]AccessGroup, error) { var allGroups []AccessGroup page := 0 - pageSize := 10 for { - response, err := c.GetAccessGroupsByPage(page, pageSize) + response, err := c.GetAccessGroupsByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -114,6 +114,23 @@ func (c *AccessGroupsService) Get(id string) (*AccessGroup, error) { return &accessGroup, nil } +// GetByName retrieves an access group by its name +// name: The name of the access group to retrieve +// Returns the access group and any error that occurred +func (c *AccessGroupsService) GetByName(name string) (*AccessGroup, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + for _, item := range items { + if item.Name == name { + return &item, nil + } + } + return nil, errors.New("access group not found") +} + // Create creates a new access group in the CloudConnexa API. // It returns the created access group with its assigned ID. func (c *AccessGroupsService) Create(accessGroup *AccessGroup) (*AccessGroup, error) { diff --git a/cloudconnexa/cloudconnexa.go b/cloudconnexa/cloudconnexa.go index b53968d..9538629 100644 --- a/cloudconnexa/cloudconnexa.go +++ b/cloudconnexa/cloudconnexa.go @@ -15,7 +15,8 @@ import ( ) const ( - userAgent = "cloudconnexa-go" + userAgent = "cloudconnexa-go" + defaultPageSize = 100 ) // Client represents a CloudConnexa API client with all service endpoints. diff --git a/cloudconnexa/devices.go b/cloudconnexa/devices.go index 3b60e41..819a478 100644 --- a/cloudconnexa/devices.go +++ b/cloudconnexa/devices.go @@ -159,10 +159,9 @@ func (d *DevicesService) GetByPage(page int, pageSize int) (*DevicePageResponse, func (d *DevicesService) ListAll() ([]DeviceDetail, error) { var allDevices []DeviceDetail page := 0 - pageSize := 100 // Use maximum page size for efficiency for { - response, err := d.GetByPage(page, pageSize) + response, err := d.GetByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -232,13 +231,12 @@ func (d *DevicesService) Update(deviceID string, updateRequest DeviceUpdateReque func (d *DevicesService) ListByUserID(userID string) ([]DeviceDetail, error) { var allDevices []DeviceDetail page := 0 - pageSize := 100 for { options := DeviceListOptions{ UserID: userID, Page: page, - Size: pageSize, + Size: defaultPageSize, } response, err := d.List(options) diff --git a/cloudconnexa/devices_test.go b/cloudconnexa/devices_test.go index 966a547..a3e4d95 100644 --- a/cloudconnexa/devices_test.go +++ b/cloudconnexa/devices_test.go @@ -54,7 +54,7 @@ func TestDevicesService_List(t *testing.T) { }, NumberOfElements: 2, Page: 0, - Size: 10, + Size: 100, Success: true, TotalElements: 2, TotalPages: 1, @@ -71,7 +71,7 @@ func TestDevicesService_List(t *testing.T) { // Test the List method options := DeviceListOptions{ Page: 0, - Size: 10, + Size: 100, } result, err := client.Devices.List(options) if err != nil { diff --git a/cloudconnexa/dns_records.go b/cloudconnexa/dns_records.go index 72941b0..ec724be 100644 --- a/cloudconnexa/dns_records.go +++ b/cloudconnexa/dns_records.go @@ -83,11 +83,10 @@ func (c *DNSRecordsService) GetByID(recordID string) (*DNSRecord, error) { // GetDNSRecord retrieves a specific DNS record by ID using pagination search. // Deprecated: Use GetByID() instead for better performance with the direct API endpoint. func (c *DNSRecordsService) GetDNSRecord(recordID string) (*DNSRecord, error) { - pageSize := 10 page := 0 for { - response, err := c.GetByPage(page, pageSize) + response, err := c.GetByPage(page, defaultPageSize) if err != nil { return nil, err } diff --git a/cloudconnexa/dns_records_direct_test.go b/cloudconnexa/dns_records_direct_test.go index abc2097..2b3cafd 100644 --- a/cloudconnexa/dns_records_direct_test.go +++ b/cloudconnexa/dns_records_direct_test.go @@ -2,10 +2,11 @@ package cloudconnexa import ( "encoding/json" - "golang.org/x/time/rate" "net/http" "net/http/httptest" "testing" + + "golang.org/x/time/rate" ) // createTestDNSClient creates a test client with the given server for DNS testing @@ -114,7 +115,7 @@ func TestDNSRecordsService_GetByID_vs_GetDNSRecord(t *testing.T) { {ID: "record-123", Domain: "example.com"}, }, Page: 0, - Size: 10, + Size: 100, TotalPages: 1, } w.Header().Set("Content-Type", "application/json") diff --git a/cloudconnexa/host_applications.go b/cloudconnexa/host_applications.go index eabef51..e0ddb21 100644 --- a/cloudconnexa/host_applications.go +++ b/cloudconnexa/host_applications.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -86,10 +87,9 @@ func (c *HostApplicationsService) GetApplicationsByPage(page int, pageSize int) func (c *HostApplicationsService) List() ([]ApplicationResponse, error) { var allApplications []ApplicationResponse page := 0 - pageSize := 10 for { - response, err := c.GetApplicationsByPage(page, pageSize) + response, err := c.GetApplicationsByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -124,6 +124,30 @@ func (c *HostApplicationsService) Get(id string) (*ApplicationResponse, error) { return &application, nil } +// GetByName retrieves an application by its name +// name: The name of the application to retrieve +// Returns the application and any error that occurred +func (c *HostApplicationsService) GetByName(name string) (*ApplicationResponse, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + filtered := make([]ApplicationResponse, 0) + for _, item := range items { + if item.Name == name { + filtered = append(filtered, item) + } + } + if len(filtered) > 1 { + return nil, errors.New("different host applications found with name: " + name) + } + if len(filtered) == 1 { + return &filtered[0], nil + } + return nil, errors.New("host application not found") +} + // Create creates a new host application. func (c *HostApplicationsService) Create(application *Application) (*ApplicationResponse, error) { applicationJSON, err := json.Marshal(application) diff --git a/cloudconnexa/host_connectors.go b/cloudconnexa/host_connectors.go index a8b1d64..e669857 100644 --- a/cloudconnexa/host_connectors.go +++ b/cloudconnexa/host_connectors.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -101,10 +102,9 @@ func (c *HostConnectorsService) List() ([]HostConnector, error) { func (c *HostConnectorsService) ListByHostID(hostID string) ([]HostConnector, error) { var allConnectors []HostConnector page := 0 - pageSize := 10 for { - response, err := c.GetByPageAndHostID(page, pageSize, hostID) + response, err := c.GetByPageAndHostID(page, defaultPageSize, hostID) if err != nil { return nil, err } @@ -140,6 +140,30 @@ func (c *HostConnectorsService) GetByID(id string) (*HostConnector, error) { return &connector, nil } +// GetByName retrieves a connector by its name +// name: The name of the connector to retrieve +// Returns the connector and any error that occurred +func (c *HostConnectorsService) GetByName(name string) (*HostConnector, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + filtered := make([]HostConnector, 0) + for _, item := range items { + if item.Name == name { + filtered = append(filtered, item) + } + } + if len(filtered) > 1 { + return nil, errors.New("different host connectors found with name: " + name) + } + if len(filtered) == 1 { + return &filtered[0], nil + } + return nil, errors.New("host connector not found") +} + // GetProfile retrieves the profile configuration for a host connector. func (c *HostConnectorsService) GetProfile(id string) (string, error) { req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/hosts/connectors/%s/profile", c.client.GetV1Url(), id), nil) diff --git a/cloudconnexa/host_ip_services.go b/cloudconnexa/host_ip_services.go index 5ed73a5..2ef6806 100644 --- a/cloudconnexa/host_ip_services.go +++ b/cloudconnexa/host_ip_services.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -97,10 +98,9 @@ func (c *HostIPServicesService) GetIPByPage(page int, pageSize int) (HostIPServi func (c *HostIPServicesService) List() ([]HostIPServiceResponse, error) { var allIPServices []HostIPServiceResponse page := 0 - pageSize := 10 for { - response, err := c.GetIPByPage(page, pageSize) + response, err := c.GetIPByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -135,6 +135,30 @@ func (c *HostIPServicesService) Get(id string) (*HostIPServiceResponse, error) { return &service, nil } +// GetByName retrieves an IP Service by its name +// name: The name of the IP Service to retrieve +// Returns the IP Service and any error that occurred +func (c *HostIPServicesService) GetByName(name string) (*HostIPServiceResponse, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + filtered := make([]HostIPServiceResponse, 0) + for _, item := range items { + if item.Name == name { + filtered = append(filtered, item) + } + } + if len(filtered) > 1 { + return nil, errors.New("different host IP services found with name: " + name) + } + if len(filtered) == 1 { + return &filtered[0], nil + } + return nil, errors.New("host IP service not found") +} + // Create creates a new IP service. func (c *HostIPServicesService) Create(ipService *IPService) (*HostIPServiceResponse, error) { ipServiceJSON, err := json.Marshal(ipService) diff --git a/cloudconnexa/host_ip_services_dto_test.go b/cloudconnexa/host_ip_services_dto_test.go index 2311e98..2486a08 100644 --- a/cloudconnexa/host_ip_services_dto_test.go +++ b/cloudconnexa/host_ip_services_dto_test.go @@ -2,10 +2,11 @@ package cloudconnexa import ( "encoding/json" - "golang.org/x/time/rate" "net/http" "net/http/httptest" "testing" + + "golang.org/x/time/rate" ) // createTestHostIPServicesClient creates a test client with the given server for host IP services testing @@ -151,7 +152,7 @@ func TestHostIPServicesService_List_UpdatedDTO(t *testing.T) { }, NumberOfElements: 2, Page: 0, - Size: 10, + Size: 100, Success: true, TotalElements: 2, TotalPages: 1, @@ -165,7 +166,7 @@ func TestHostIPServicesService_List_UpdatedDTO(t *testing.T) { client := createTestHostIPServicesClient(server) // Test the GetIPByPage method directly to avoid pagination issues - result, err := client.HostIPServices.GetIPByPage(0, 10) + result, err := client.HostIPServices.GetIPByPage(0, 100) if err != nil { t.Fatalf("Expected no error, got %v", err) } diff --git a/cloudconnexa/hosts.go b/cloudconnexa/hosts.go index d173dcb..e4988d0 100644 --- a/cloudconnexa/hosts.go +++ b/cloudconnexa/hosts.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -55,11 +56,10 @@ func (c *HostsService) GetHostsByPage(page int, size int) (HostPageResponse, err // List retrieves all hosts. func (c *HostsService) List() ([]Host, error) { var allHosts []Host - pageSize := 10 page := 0 for { - response, err := c.GetHostsByPage(page, pageSize) + response, err := c.GetHostsByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -95,6 +95,23 @@ func (c *HostsService) Get(id string) (*Host, error) { return &host, nil } +// GetByName retrieves a host by its name +// name: The name of the host to retrieve +// Returns the host and any error that occurred +func (c *HostsService) GetByName(name string) (*Host, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + for _, item := range items { + if item.Name == name { + return &item, nil + } + } + return nil, errors.New("host not found") +} + // Create creates a new host. func (c *HostsService) Create(host Host) (*Host, error) { hostJSON, err := json.Marshal(host) diff --git a/cloudconnexa/location_contexts.go b/cloudconnexa/location_contexts.go index 68d5843..6d16527 100644 --- a/cloudconnexa/location_contexts.go +++ b/cloudconnexa/location_contexts.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -81,10 +82,9 @@ func (c *LocationContextsService) GetLocationContextByPage(page int, pageSize in func (c *LocationContextsService) List() ([]LocationContext, error) { var allLocationContexts []LocationContext page := 0 - pageSize := 10 for { - response, err := c.GetLocationContextByPage(page, pageSize) + response, err := c.GetLocationContextByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -119,6 +119,23 @@ func (c *LocationContextsService) Get(id string) (*LocationContext, error) { return &locationContext, nil } +// GetByName retrieves a location context by its name +// name: The name of the location context to retrieve +// Returns the location context and any error that occurred +func (c *LocationContextsService) GetByName(name string) (*LocationContext, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + for _, item := range items { + if item.Name == name { + return &item, nil + } + } + return nil, errors.New("location context not found") +} + // Create creates a new location context. func (c *LocationContextsService) Create(locationContext *LocationContext) (*LocationContext, error) { locationContextJSON, err := json.Marshal(locationContext) diff --git a/cloudconnexa/network_applications.go b/cloudconnexa/network_applications.go index 12a6b6b..01314db 100644 --- a/cloudconnexa/network_applications.go +++ b/cloudconnexa/network_applications.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -35,10 +36,9 @@ func (c *NetworkApplicationsService) GetApplicationsByPage(page int, pageSize in func (c *NetworkApplicationsService) List() ([]ApplicationResponse, error) { var allApplications []ApplicationResponse page := 0 - pageSize := 10 for { - response, err := c.GetApplicationsByPage(page, pageSize) + response, err := c.GetApplicationsByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -73,6 +73,30 @@ func (c *NetworkApplicationsService) Get(id string) (*ApplicationResponse, error return &application, nil } +// GetByName retrieves a network application by its name +// name: The name of the network application to retrieve +// Returns the network application and any error that occurred +func (c *NetworkApplicationsService) GetByName(name string) (*ApplicationResponse, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + filtered := make([]ApplicationResponse, 0) + for _, item := range items { + if item.Name == name { + filtered = append(filtered, item) + } + } + if len(filtered) > 1 { + return nil, errors.New("different network applications found with name: " + name) + } + if len(filtered) == 1 { + return &filtered[0], nil + } + return nil, errors.New("network application not found") +} + // Create creates a new network application. func (c *NetworkApplicationsService) Create(application *Application) (*ApplicationResponse, error) { applicationJSON, err := json.Marshal(application) diff --git a/cloudconnexa/network_connectors.go b/cloudconnexa/network_connectors.go index 87590e6..8cd2687 100644 --- a/cloudconnexa/network_connectors.go +++ b/cloudconnexa/network_connectors.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" "net/url" @@ -148,10 +149,9 @@ func (c *NetworkConnectorsService) Update(connector NetworkConnector) (*NetworkC func (c *NetworkConnectorsService) List() ([]NetworkConnector, error) { var allConnectors []NetworkConnector page := 0 - pageSize := 10 for { - response, err := c.GetByPage(page, pageSize) + response, err := c.GetByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -170,10 +170,9 @@ func (c *NetworkConnectorsService) List() ([]NetworkConnector, error) { func (c *NetworkConnectorsService) ListByNetworkID(networkID string) ([]NetworkConnector, error) { var allConnectors []NetworkConnector page := 0 - pageSize := 10 for { - response, err := c.GetByPageAndNetworkID(page, pageSize, networkID) + response, err := c.GetByPageAndNetworkID(page, defaultPageSize, networkID) if err != nil { return nil, err } @@ -209,6 +208,30 @@ func (c *NetworkConnectorsService) GetByID(id string) (*NetworkConnector, error) return &connector, nil } +// GetByName retrieves a network connector by its name +// name: The name of the network connector to retrieve +// Returns the network connector and any error that occurred +func (c *NetworkConnectorsService) GetByName(name string) (*NetworkConnector, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + filtered := make([]NetworkConnector, 0) + for _, item := range items { + if item.Name == name { + filtered = append(filtered, item) + } + } + if len(filtered) > 1 { + return nil, errors.New("different network connectors found with name: " + name) + } + if len(filtered) == 1 { + return &filtered[0], nil + } + return nil, errors.New("network connector not found") +} + // GetProfile retrieves the profile configuration for a specific network connector. func (c *NetworkConnectorsService) GetProfile(id string) (string, error) { req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/networks/connectors/%s/profile", c.client.GetV1Url(), id), nil) diff --git a/cloudconnexa/network_ip_services.go b/cloudconnexa/network_ip_services.go index 510a3d8..f99ce8e 100644 --- a/cloudconnexa/network_ip_services.go +++ b/cloudconnexa/network_ip_services.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -63,10 +64,9 @@ func (c *NetworkIPServicesService) GetIPByPage(page int, pageSize int) (NetworkI func (c *NetworkIPServicesService) List() ([]NetworkIPServiceResponse, error) { var allIPServices []NetworkIPServiceResponse page := 0 - pageSize := 10 for { - response, err := c.GetIPByPage(page, pageSize) + response, err := c.GetIPByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -103,6 +103,30 @@ func (c *NetworkIPServicesService) Get(id string) (*NetworkIPServiceResponse, er return &service, nil } +// GetByName retrieves a network IP service by its name +// name: The name of the network IP service to retrieve +// Returns the network IP service and any error that occurred +func (c *NetworkIPServicesService) GetByName(name string) (*NetworkIPServiceResponse, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + filtered := make([]NetworkIPServiceResponse, 0) + for _, item := range items { + if item.Name == name { + filtered = append(filtered, item) + } + } + if len(filtered) > 1 { + return nil, errors.New("different network IP services found with name: " + name) + } + if len(filtered) == 1 { + return &filtered[0], nil + } + return nil, errors.New("network IP service not found") +} + // Create creates a new IP service // ipService: The IP service configuration to create // Returns the created IP service and any error that occurred diff --git a/cloudconnexa/networks.go b/cloudconnexa/networks.go index dafbc7a..c3412e8 100644 --- a/cloudconnexa/networks.go +++ b/cloudconnexa/networks.go @@ -3,6 +3,7 @@ package cloudconnexa import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" ) @@ -72,11 +73,10 @@ func (c *NetworksService) GetByPage(page int, size int) (NetworkPageResponse, er // Returns a slice of all networks and any error that occurred func (c *NetworksService) List() ([]Network, error) { var allNetworks []Network - pageSize := 10 page := 0 for { - response, err := c.GetByPage(page, pageSize) + response, err := c.GetByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -114,6 +114,23 @@ func (c *NetworksService) Get(id string) (*Network, error) { return &network, nil } +// GetByName retrieves a network by its name +// name: The name of the network to retrieve +// Returns the network and any error that occurred +func (c *NetworksService) GetByName(name string) (*Network, error) { + items, err := c.List() + if err != nil { + return nil, err + } + + for _, item := range items { + if item.Name == name { + return &item, nil + } + } + return nil, errors.New("network not found") +} + // Create creates a new network. // network: The network configuration to create // Returns the created network and any error that occurred diff --git a/cloudconnexa/routes.go b/cloudconnexa/routes.go index fc9992b..818580e 100644 --- a/cloudconnexa/routes.go +++ b/cloudconnexa/routes.go @@ -62,11 +62,10 @@ func (c *RoutesService) GetByPage(networkID string, page int, size int) (RoutePa // Returns a slice of routes and any error that occurred func (c *RoutesService) List(networkID string) ([]Route, error) { var allRoutes []Route - pageSize := 10 page := 0 for { - response, err := c.GetByPage(networkID, page, pageSize) + response, err := c.GetByPage(networkID, page, defaultPageSize) if err != nil { return nil, err } diff --git a/cloudconnexa/sessions_test.go b/cloudconnexa/sessions_test.go index 5b82a48..c24d608 100644 --- a/cloudconnexa/sessions_test.go +++ b/cloudconnexa/sessions_test.go @@ -36,8 +36,8 @@ func TestSessionsService_List(t *testing.T) { // Check query parameters query := r.URL.Query() - if query.Get("size") != "10" { - t.Errorf("Expected size=10, got %s", query.Get("size")) + if query.Get("size") != "100" { + t.Errorf("Expected size=100, got %s", query.Get("size")) } // Mock response @@ -67,7 +67,7 @@ func TestSessionsService_List(t *testing.T) { // Test the List method options := SessionsListOptions{ - Size: 10, + Size: 100, } result, err := client.Sessions.List(options) if err != nil { diff --git a/cloudconnexa/user_groups.go b/cloudconnexa/user_groups.go index 8872d07..7e7396b 100644 --- a/cloudconnexa/user_groups.go +++ b/cloudconnexa/user_groups.go @@ -67,11 +67,10 @@ func (c *UserGroupsService) GetByPage(page int, pageSize int) (UserGroupPageResp // Returns a slice of user groups and any error that occurred func (c *UserGroupsService) List() ([]UserGroup, error) { var allUserGroups []UserGroup - pageSize := 10 page := 0 for { - response, err := c.GetByPage(page, pageSize) + response, err := c.GetByPage(page, defaultPageSize) if err != nil { return nil, err } diff --git a/cloudconnexa/user_groups_direct_test.go b/cloudconnexa/user_groups_direct_test.go index 82f19c8..1682d29 100644 --- a/cloudconnexa/user_groups_direct_test.go +++ b/cloudconnexa/user_groups_direct_test.go @@ -2,10 +2,11 @@ package cloudconnexa import ( "encoding/json" - "golang.org/x/time/rate" "net/http" "net/http/httptest" "testing" + + "golang.org/x/time/rate" ) // createTestUserGroupsClient creates a test client with the given server for user groups testing @@ -125,7 +126,7 @@ func TestUserGroupsService_GetByID_vs_Get(t *testing.T) { {ID: "group-123", Name: "Test Group"}, }, Page: 0, - Size: 10, + Size: 100, TotalPages: 1, } w.Header().Set("Content-Type", "application/json") diff --git a/cloudconnexa/users.go b/cloudconnexa/users.go index 134fa7b..755f969 100644 --- a/cloudconnexa/users.go +++ b/cloudconnexa/users.go @@ -81,11 +81,10 @@ func (c *UsersService) GetByPage(page int, pageSize int) (UserPageResponse, erro // role: The role to filter by // Returns the user and any error that occurred func (c *UsersService) List(username string, role string) (*User, error) { - pageSize := 10 page := 0 for { - response, err := c.GetByPage(page, pageSize) + response, err := c.GetByPage(page, defaultPageSize) if err != nil { return nil, err } @@ -138,11 +137,10 @@ func (c *UsersService) GetByID(userID string) (*User, error) { // username: The username to search for // Returns the user and any error that occurred func (c *UsersService) GetByUsername(username string) (*User, error) { - pageSize := 10 page := 0 for { - response, err := c.GetByPage(page, pageSize) + response, err := c.GetByPage(page, defaultPageSize) if err != nil { return nil, err } diff --git a/e2e/client_test.go b/e2e/client_test.go index 722cd0f..ae5d120 100644 --- a/e2e/client_test.go +++ b/e2e/client_test.go @@ -27,7 +27,7 @@ func validateEnvVar(t *testing.T, envVar string) { // Environment variable names for client configuration const ( - HostEnvVar = "OVPN_HOST" + HostEnvVar = "CLOUDCONNEXA_BASE_URL" ClientIDEnvVar = "CLOUDCONNEXA_CLIENT_ID" ClientSecretEnvVar = "CLOUDCONNEXA_CLIENT_SECRET" //nolint:gosec // This is an environment variable name, not a credential ) @@ -53,7 +53,7 @@ func setUpClient(t *testing.T) *cloudconnexa.Client { // It verifies that networks can be retrieved successfully func TestListNetworks(t *testing.T) { c := setUpClient(t) - response, err := c.Networks.GetByPage(0, 10) + response, err := c.Networks.GetByPage(0, 100) require.NoError(t, err) fmt.Printf("found %d networks\n", len(response.Content)) }