Skip to content

test(entities/models): add unit tests for EntityInstance and EntityWi…#6245

Open
dakshhhhh16 wants to merge 1 commit intomindersec:mainfrom
dakshhhhh16:test/unit-entities-models
Open

test(entities/models): add unit tests for EntityInstance and EntityWi…#6245
dakshhhhh16 wants to merge 1 commit intomindersec:mainfrom
dakshhhhh16:test/unit-entities-models

Conversation

@dakshhhhh16
Copy link
Copy Markdown
Contributor

@dakshhhhh16 dakshhhhh16 commented Apr 1, 2026

Summary

Adds a complete unit-test suite for internal/entities/models, the package
that defines the core domain structs (EntityInstance, EntityWithProperties)
shared across the rule-engine, reconcilers, and event-bus.

Tests Added

Test What it covers
TestEntityInstance_FieldsPreserved All fields set on EntityInstance survive a round-trip
TestEntityInstance_ZeroValue Zero-value struct is safe to read without panics
TestEntityWithProperties_EntityAccessor .Entity field returns the embedded EntityInstance
TestEntityWithProperties_PropertiesAccessor .Properties accessor returns the correct property map
TestEntityWithProperties_NilProperties nil properties map does not panic on access
TestEntityWithProperties_MultipleProperties Multiple properties are all stored and retrievable
TestEntityInstance_TypeAndProjectPreserved Type and ProjectID fields survive construction

Why This Matters

EntityInstance and EntityWithProperties are the most widely-referenced
structs in the Minder rule-engine. Tests here prevent structural regressions
(e.g. a renamed or removed field) from going undetected until runtime.

Copilot AI review requested due to automatic review settings April 1, 2026 22:47
@dakshhhhh16 dakshhhhh16 requested a review from a team as a code owner April 1, 2026 22:47
Copy link
Copy Markdown
Contributor

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

Adds a new unit test file for internal/entities/models, covering EntityInstance / EntityWithProperties string formatting, property update behavior, and the NeedsPropertyLoad heuristic.

Changes:

  • Added tests validating EntityInstance.String() includes key identifiers.
  • Added tests for NewEntityWithPropertiesFromInstance, UpdateProperties, and NeedsPropertyLoad.
  • Added a test validating EntityWithProperties.String() formatting includes the expected “ENTITY” keyword.

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

Comment on lines +16 to +22
func TestEntityInstanceString_ContainsName(t *testing.T) {
t.Parallel()
ei := EntityInstance{
ID: uuid.New(),
Type: minderv1.Entity_ENTITY_REPOSITORIES,
Name: "myorg/myrepo",
ProviderID: uuid.New(),
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

PR description lists test cases like TestEntityInstance_FieldsPreserved / TestEntityInstance_ZeroValue / accessor tests, but the added file defines different tests (mostly String()/NeedsPropertyLoad()/UpdateProperties). Please update the PR description (or rename/adjust tests) so the described coverage matches what is actually being added.

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +61
props := properties.NewProperties(map[string]any{"key": "value"})
ewp := NewEntityWithPropertiesFromInstance(ei, props)
if ewp.Entity.Name != ei.Name {
t.Errorf("entity name = %q, want %q", ewp.Entity.Name, ei.Name)
}
if ewp.Properties != props {
t.Error("properties not stored correctly")
}
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

TestNewEntityWithPropertiesFromInstance_RoundTrip asserts ewp.Properties == props (pointer identity). This is brittle because a future implementation could legitimately clone/copy properties while preserving behavior. Prefer asserting on observable behavior (e.g., that expected keys/values are present and Len() matches) rather than pointer equality.

Copilot uses AI. Check for mistakes.
}
s := ewp.String()
if !strings.Contains(s, "ENTITY") {
t.Errorf("EntityWithProperties.String() = %q, want prefix 'ENTITY'", s)
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

The assertion uses strings.Contains(s, "ENTITY") but the failure message says it wants a prefix ENTITY. Either change the check to HasPrefix or adjust the message to match the actual assertion to avoid confusion when debugging failures.

Suggested change
t.Errorf("EntityWithProperties.String() = %q, want prefix 'ENTITY'", s)
t.Errorf("EntityWithProperties.String() = %q, want to contain 'ENTITY'", s)

Copilot uses AI. Check for mistakes.
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 58.345% (+0.04%) from 58.306%
when pulling 3376f86 on dakshhhhh16:test/unit-entities-models
into cac62d5 on mindersec:main.

@evankanderson
Copy link
Copy Markdown
Member

It looks like this adds minor coverage for Properties.String, EntityInstance.String, [EntityWithProperties.String](https://coveralls.io/builds/78592056/source?filename=internal%2Fentities%2Fmodels%2Fmodels.go#L68), and EntityWithProperties.UpdateProperties.

Unfortunately, it seems like Properties.String doesn't test the loop in that method -- the others do test the methods, but all the methods are trivial (i.e. single-line fmt.Sprintf or assignment). Given that these implement fmt.Stringer for the sake of debugging, I'm not sure this is adding much meaningful coverage.

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.

4 participants