[test] Add tests for difc.labels (CheckFlow, ViolationError, Clone, Union)#1370
Merged
[test] Add tests for difc.labels (CheckFlow, ViolationError, Clone, Union)#1370
Conversation
Cover previously untested functions in the difc labels package: - Label.Union, Label.Clone, Label.GetTags - SecrecyLabel.CheckFlow with all nil/edge-case branches - IntegrityLabel.CheckFlow with all nil/edge-case branches - SecrecyLabel.Clone and IntegrityLabel.Clone (nil receiver cases) - NewSecrecyLabelWithTags and NewIntegrityLabelWithTags - ViolationError.Error() with all branching paths (SecrecyViolation, IntegrityViolation write/read, missing/extra tags) - ViolationError.Detailed() and interface compliance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds focused unit tests for the core DIFC label primitives in internal/difc/labels.go, improving confidence in secrecy/integrity flow checks and DIFC violation messaging.
Changes:
- Introduces comprehensive table-driven tests for
Label,SecrecyLabel, andIntegrityLabeloperations (Union/Clone/GetTags/CheckFlow/CanFlowTo). - Adds branch coverage for
ViolationError.Error()andViolationError.Detailed(), including interface compliance.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+16
to
+17
| other []Tag // nil means nil *Label is passed | ||
| nilOther bool |
There was a problem hiding this comment.
The struct field comment for other []Tag is misleading: in this table nil for other produces an empty Label (since nilOther controls whether a nil *Label is passed). Consider updating the comment and/or removing the redundant nilOther flag to avoid confusion when adding new cases.
Suggested change
| other []Tag // nil means nil *Label is passed | |
| nilOther bool | |
| other []Tag // nil means "other" is an empty label (no tags) | |
| nilOther bool // when true, a nil *Label is passed to Union |
This was referenced Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Coverage Improvement:
internal/difc/labels.goFunction Analyzed
internal/difclabels.goWhy This Function?
labels.goimplements the core DIFC (Decentralized Information Flow Control) label primitives —Label,SecrecyLabel,IntegrityLabel, andViolationError. Despite being central to the security model, several key functions had no direct test coverage:CheckFlowmethods (used byevaluator.gobut never tested in isolation)ViolationError.Error()— 4-way branch covering secrecy/integrity × read/write scenariosViolationError.Detailed()— extendsError()with tag contextClonemethods for both label types (nil-receiver edge cases)Label.Union,Label.Clone,Label.GetTagsbase-level operationsNewSecrecyLabelWithTags/NewIntegrityLabelWithTagsconstructorsTests Added
New file:
internal/difc/labels_test.goTestLabel_Union— merging tags, nil other, overlapping tags, empty inputsTestLabel_Clone— independence from original, empty label cloneTestLabel_GetTags— correct tag enumerationTestSecrecyLabel_CheckFlow— nil receiver, nil target, subset/superset, multi-tag violationsTestIntegrityLabel_CheckFlow— nil receiver, nil target, superset/missing tag scenariosTestSecrecyLabel_Clone— nil receiver, nil inner Label, independenceTestIntegrityLabel_Clone— nil receiver, nil inner Label, independenceTestNewSecrecyLabelWithTags/TestNewIntegrityLabelWithTags— constructors with tags and nilTestViolationError_Error— all 4 branches (secrecy with/without extra tags; integrity write/read with/without missing tags)TestViolationError_Detailed— tag context, secrecy vs integrity, length checkTestViolationError_implementsError— interface complianceTestSecrecyLabel_CanFlowTo_NilCases— nil receiver and nil argument edge casesTestIntegrityLabel_CanFlowTo_NilCases— nil receiver and nil argument edge casesTesting Approach
All tests follow the project's table-driven test pattern with
testify/assertandtestify/requireassertions. Nil-receiver method calls are exercised directly using typednilpointers (safe since the implementations explicitly guard against nil receivers).Generated by Test Coverage Improver