Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

TEST: `ConnectAndGetToken` Returns Error on Non-200 Response

Open Beginner friendly
#554 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
testing

Research direction

Start in keycloak_client.go at ConnectAndGetToken, then use an httptest.Server that returns 401 with the documented JSON body. Verify the returned error is non-nil, includes the 401 status, and has KindAPI classification. Done means the test reliably covers the non-200 response path and the full Keycloak client package has this critical case protected.

Written by the indexing model from the issue text.

Description

Reason/Context
Description

keycloak_client.go ConnectAndGetToken has no tests at all. The entire
Keycloak client package is untested. The most critical path to test is when
Keycloak returns a non-200 status (wrong credentials, realm not found, server
error) — the function should return a KindAPI error with the HTTP status code
and body. Currently nothing verifies this.

Why Necessary

Wrong credentials is the single most common failure a new user encounters. If
this error path regresses — e.g. the function panics, returns a nil error, or
swallows the body — users get no feedback and assume the server is down.

What If Not Present

A change to the response-parsing code (e.g. switching JSON library, restructuring
the token response) could silently break authentication for all users and no test
would catch it before release.

Diagram
sequenceDiagram
    participant T  as Test
    participant KC as keycloakClient
    participant TS as httptest.Server

    T->>TS: register handler → always return 401 {"error":"unauthorized"}
    T->>KC: NewKeycloakClient(server.URL, "id", "secret")
    T->>KC: ConnectAndGetToken()

    KC->>TS: POST /protocol/openid-connect/token
    TS-->>KC: 401 {"error":"unauthorized"}

    KC-->>T: error (KindAPI)

    T->>T: assert error != nil 
    T->>T: assert error contains "401" 
    T->>T: assert KindOf(err) == KindAPI 

Description

N/A

Implementation ideas

No response

Dominant language
Go
Stars
57
Forks
72
Avg merge
1d 35m
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microcks/microcks-cli

All issues in microcks/microcks-cli

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.