Skip to content

test: add unit tests for connectors validation functions of microcks_client.go#289

Open
patilpratik1905 wants to merge 1 commit intomicrocks:masterfrom
patilpratik1905:tests/add_microcks_client_tests
Open

test: add unit tests for connectors validation functions of microcks_client.go#289
patilpratik1905 wants to merge 1 commit intomicrocks:masterfrom
patilpratik1905:tests/add_microcks_client_tests

Conversation

@patilpratik1905
Copy link
Copy Markdown

Description

Problem :

The pkg/connectors package had no test coverage for critical validation functions:

  • ensureValidOperationsList
  • ensureValidOperationsHeaders
  • ensureValieOAuth2Context

These functions act as gatekeepers for validating JSON inputs before sending data to Microcks APIs. Without tests, malformed inputs could go undetected.

Solution :

Added 33 table-driven unit tests in:
New file: pkg/connectors/microcks_client_test.go

TestEnsureValidOperationsList (10 tests)

  • Valid array with single and multiple entries
  • Valid empty array
  • Invalid: plain string, object, malformed JSON, missing bracket
  • Invalid: array of numbers instead of strings
  • Valid: special characters in operation names

TestEnsureValidOperationsHeaders (10 tests)

  • Valid: single operation, multiple operations, multiple headers per operation
  • Valid: empty map, empty header array per operation
  • Invalid: malformed JSON, plain string, array instead of map
  • Invalid: wrong value type (string instead of array), missing closing brace

TestEnsureValidOAuth2Context (13 tests)

  • Valid: all three supported grant types (PASSWORD, CLIENT_CREDENTIALS, REFRESH_TOKEN)
  • Valid: optional scopes field, minimal required fields
  • Invalid: unsupported grant type, empty grant type, missing grant type
  • Invalid: wrong casing on grant type (case-sensitive validation)
  • Invalid: malformed JSON, plain string, empty string, array instead of object

Related issue(s)

NA

…client.go

Signed-off-by: Pratik Patil <pratikgpatil1905@gmail.com>
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.

1 participant