Skip to content

feat: interfaces, resolve resources by name, tests#57

Merged
avirtopeanu-ionos merged 4 commits intov2from
feat/interfaces
Mar 3, 2026
Merged

feat: interfaces, resolve resources by name, tests#57
avirtopeanu-ionos merged 4 commits intov2from
feat/interfaces

Conversation

@avirtopeanu-ionos
Copy link
Contributor

@avirtopeanu-ionos avirtopeanu-ionos commented Feb 26, 2026

  • Add generic Go interfaces (Identifiable, HasHref, Resource, Listable[T], HasProperties[P]) that abstract the common accessor patterns across all generated SDK model types
  • Add Resolve() — a generic helper that accepts a name or UUID and resolves it to a resource ID via a caller-supplied list callback, with clear errors for zero/ambiguous matches
  • Add CI workflow for the shared/ package (tests with race detector + coverage)
  • Add testable examples that appear in godoc and validate usage with DNS-like types

Example:

  // Different SDK types (zones, records, or any product) satisfy the same
  // interfaces — they can be combined and operated on uniformly.
  var all []shared.Resource
  for i := range zones {
      all = append(all, &zones[i])   // *dns.ZoneRead satisfies shared.Resource
  }
  for i := range records {
      all = append(all, &records[i]) // *dns.RecordRead satisfies shared.Resource
  }
  for _, r := range all {
      fmt.Println(r.GetId(), r.GetHref()) // works on both types
  }

  // Find a specific resource by ID.
  zone, ok := shared.FindByID(all.GetItems(), "550e8400-e29b-41d4-a716-446655440000")
  if ok {
      fmt.Println(zone.GetProperties().GetZoneName())
  }

  // Resolve a name-or-UUID to an ID. If already a UUID, no API call is made.
  id, err := shared.Resolve(ctx, "example.com", func(ctx context.Context, name string) ([]dns.ZoneRead, error) {
      result, _, err := client.ZonesApi.ZonesGet(ctx).FilterZoneName(name).Limit(2).Execute()
      if err != nil {
          return nil, err
      }
      return result.GetItems(), nil
  })

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a comprehensive set of generic utilities and interfaces to the shared package that abstract common patterns across all generated IONOS Cloud SDK types. The additions enable type-safe, generic operations on SDK resources without requiring manual type conversions or boilerplate code.

Changes:

  • Added five generic interfaces (Identifiable, HasHref, Resource, Listable[T], HasProperties[P]) that SDK types satisfy through their generated accessor methods
  • Added utility functions (ExtractIDs, FindByID, ListItems, Properties) that work directly with value-type slices returned by SDK GetItems() methods
  • Added Resolve() function that resolves human-readable names to resource IDs, with UUID detection to skip unnecessary API calls
  • Added comprehensive test coverage with unit tests and executable documentation examples
  • Added CI workflow for automated testing with race detection and coverage reporting

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
shared/interfaces.go Defines generic interfaces (Identifiable, HasHref, Resource, Listable, HasProperties) and utility functions (ExtractIDs, FindByID, ListItems, Properties) that work with SDK value-type slices
shared/resolve.go Implements UUID validation and name-to-ID resolution with clear error handling for zero/ambiguous matches
shared/interfaces_test.go Comprehensive unit tests for interface utilities with mock types that mirror SDK patterns
shared/resolve_test.go Unit tests covering UUID validation and all Resolve() scenarios (passthrough, single match, no match, ambiguous, errors)
shared/interfaces_example_test.go Executable godoc examples demonstrating interface usage with realistic mock SDK types
shared/resolve_example_test.go Executable godoc examples for UUID validation and name resolution
.github/workflows/shared-tests.yml CI workflow for automated testing with race detection and coverage reporting on shared package changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sonarqubecloud
Copy link

@avirtopeanu-ionos avirtopeanu-ionos merged commit 57c04a7 into v2 Mar 3, 2026
3 checks passed
@avirtopeanu-ionos avirtopeanu-ionos deleted the feat/interfaces branch March 3, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants