Skip to content

docs: make the custom-endpoint-name sample test actually test something - #2664

Open
tonyandrewmeyer wants to merge 5 commits into
canonical:mainfrom
tonyandrewmeyer:rainy/2657-test-custom-endpoint-names
Open

docs: make the custom-endpoint-name sample test actually test something#2664
tonyandrewmeyer wants to merge 5 commits into
canonical:mainfrom
tonyandrewmeyer:rainy/2657-test-custom-endpoint-names

Conversation

@tonyandrewmeyer

@tonyandrewmeyer tonyandrewmeyer commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Fixes two issues with the library docs.

The "Test custom endpoint names" test ran start and asserted a saw_start flag, so it never touched the relation endpoint and would pass just as happily against a DatabaseRequirer that ignored its endpoint argument and observed a hard-coded relation. It now fires relation_changed on the custom-named relation and asserts a DatabaseReadyEvent is emitted.

The DatabaseRequirer in "Write a library" hard-coded charm.on['database'], so custom endpoint names were first mentioned in the testing section. It now takes endpoint: str = 'database' and observes charm.on[endpoint], with a lead-in sentence explaining why the parameter exists.

That run also turned up why the sample META declares database alongside the custom endpoint. If only the custom endpoint is declared, a hard-coded requirer fails at charm construction with AttributeError("'CharmEvents' object has no attribute 'database_relation_changed'") — the test fails, but for the wrong reason. Declaring both means it fails with no DatabaseReadyEvent emitted, which is the defect the section is teaching about.

Fixes #2657

tonyandrewmeyer and others added 4 commits July 21, 2026 15:19
The "Test that the library initialises" example asserted both that no
events were emitted and that emitted_events[0] was a StartEvent, which
cannot both hold (the second would IndexError). It also passed an
un-invoked ctx.on.<event> method to run(), parametrised 'update-status'
where the attribute is update_status, and imported from my_Charm.

Assert instead that the library emits none of its own events, which is
what the surrounding prose says the test is for.
Matches the reference test in dwilding/basic-charms#8. Without the extra
endpoint declared, a requirer that hard-coded 'database' fails at charm
construction with an AttributeError on database_relation_changed, rather
than failing because no DatabaseReadyEvent was emitted -- so the example
demonstrated the wrong failure.
docs/ruff.toml sets line-length = 80, so the single-line assert in the
library-initialisation example exceeded it.
@tonyandrewmeyer
tonyandrewmeyer marked this pull request as ready for review July 27, 2026 01:24
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.

Correct the docs about testing custom endpoint names

1 participant