Skip to content

Add missing unit tests for utility functions #140

@ffalor

Description

@ffalor

Description

Several utility functions in the codebase currently lack unit test coverage. This issue tracks the effort to add comprehensive unit tests for these functions to improve code quality, prevent regressions, and ensure reliable behavior.

Motivation

  • Improve overall test coverage for utility functions
  • Prevent regressions when making changes to core utility code
  • Ensure edge cases and error conditions are properly handled
  • Maintain code quality standards across the project

Missing Unit Tests Checklist

The following utility functions need unit test coverage:

High Priority (Pure Functions)

  • IsKnown function in internal/utils/schema.go - checks if an attribute value is known and not null
  • MissingElements function in internal/utils/schema.go - compares string slices and returns elements from slice a that are missing from slice b
  • SetInt64FromAPIIfNotZero function in internal/utils/schema.go - conditionally sets Int64 values from API responses
  • SetStringFromAPIIfNotEmpty function in internal/utils/schema.go - conditionally sets String values from API responses
  • OptionalString function in internal/utils/schema.go - converts string pointer to types.String
  • MarkdownDescription function in internal/utils/schema.go - formats markdown descriptions with API scopes
  • getRoleNameFromArn function in internal/fcs/utils.go - extracts role name from AWS ARN string
  • AttributeTypes method in internal/content_update_policy/rings.go - returns attribute type mapping for ring assignment model

Medium Priority (Require Setup)

  • SliceToListTypeString function in internal/utils/schema.go - converts string slice to Terraform List type
  • SliceToListTypeObject function in internal/utils/schema.go - converts generic slice to Terraform List of objects
  • ValidateEmptyIDs function in internal/utils/schema.go - validates that set doesn't contain empty ID strings
  • ValidateEmptyIDsList function in internal/utils/schema.go - validates that list doesn't contain empty ID strings
  • ConvertModelToTerraformObject function in internal/utils/schema.go - converts model structs to Terraform objects
  • wrap method in internal/content_update_policy/rings.go - converts API model to internal ring assignment model
  • buildRingAssignmentSettings function in internal/content_update_policy/rings.go - converts internal models to API request models
  • Ring assignment validation functions in internal/content_update_policy/validation.go - complex validation logic for ring assignments and pinned versions

Implementation Notes

  • Start with high priority pure functions as they're easiest to test
  • Focus on utility functions that are widely used across the codebase
  • Ensure tests cover both happy path and edge cases
  • Follow existing test patterns in the codebase

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions