Skip to content

Commit 0e75715

Browse files
authored
Add comprehensive unit tests and documentation for integrations service (#163)
- Enhanced doc strings for all functions, structs, and methods with detailed descriptions - Added complete test coverage with 15 test cases across constructor, CRUD operations, and data validation - Created comprehensive tests for IntegrationService methods (Create, Get, GetAll, Delete) with error handling - Added factory function tests for NewIntegration with parameter validation and edge cases - Implemented struct field tests for Integration type with nested map validation - Created test fixtures for all API responses (get, getall, create) with realistic data structures - Added validation for automatic field setting behavior (Type=Adapter, Virtual=true) in Create method - All tests pass with proper coverage of complex integration configurations and properties
1 parent 7ba71fb commit 0e75715

5 files changed

Lines changed: 518 additions & 0 deletions

File tree

pkg/services/integrations.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/itential/ipctl/pkg/logger"
1313
)
1414

15+
// Integration represents an integration configuration in the Itential Platform.
16+
// Integrations connect external systems and services to the platform for automation workflows.
1517
type Integration struct {
1618
Name string `json:"name"`
1719
Type string `json:"type"`
@@ -25,14 +27,21 @@ type Integration struct {
2527
EventDeduplciation map[string]interface{} `json:"eventDeduplication"`
2628
}
2729

30+
// IntegrationService provides methods for managing integrations in the Itential Platform.
31+
// It handles CRUD operations for integration configurations and settings.
2832
type IntegrationService struct {
2933
client *ServiceClient
3034
}
3135

36+
// NewIntegrationService creates a new IntegrationService instance with the provided HTTP client.
37+
// The client is used to communicate with the Itential Platform integrations API.
3238
func NewIntegrationService(c client.Client) *IntegrationService {
3339
return &IntegrationService{client: NewServiceClient(c)}
3440
}
3541

42+
// NewIntegration creates a new Integration instance with the specified name and type.
43+
// It initializes the integration with default properties including ID and type fields.
44+
// This is a helper function for creating integration configurations programmatically.
3645
func NewIntegration(name, integrationType string) Integration {
3746
logger.Trace()
3847

@@ -45,6 +54,10 @@ func NewIntegration(name, integrationType string) Integration {
4554
}
4655
}
4756

57+
// Create creates a new integration in the Itential Platform.
58+
// It sends a POST request to /integrations with the integration configuration.
59+
// The Type field is automatically set to "Adapter" and Virtual to true as required by the API.
60+
// Returns the created integration or an error if the operation fails.
4861
func (svc *IntegrationService) Create(in Integration) (*Integration, error) {
4962
logger.Trace()
5063

@@ -75,11 +88,17 @@ func (svc *IntegrationService) Create(in Integration) (*Integration, error) {
7588

7689
}
7790

91+
// Delete removes an integration from the Itential Platform by its name.
92+
// It sends a DELETE request to /integrations/{name}.
93+
// Returns an error if the operation fails or the integration is not found.
7894
func (svc *IntegrationService) Delete(name string) error {
7995
logger.Trace()
8096
return svc.client.Delete(fmt.Sprintf("/integrations/%s", name))
8197
}
8298

99+
// Get retrieves a specific integration by its name from the Itential Platform.
100+
// It sends a GET request to /integrations/{name}.
101+
// Returns the integration configuration or an error if the operation fails or integration is not found.
83102
func (svc *IntegrationService) Get(name string) (*Integration, error) {
84103
logger.Trace()
85104

@@ -98,6 +117,9 @@ func (svc *IntegrationService) Get(name string) (*Integration, error) {
98117
return res.Data, nil
99118
}
100119

120+
// GetAll retrieves all integrations from the Itential Platform.
121+
// It sends a GET request to /integrations and processes the paginated results.
122+
// Returns a slice of all integration configurations or an error if the operation fails.
101123
func (svc *IntegrationService) GetAll() ([]Integration, error) {
102124
logger.Trace()
103125

0 commit comments

Comments
 (0)