Invental/Review lessons/Tests that can never fail

Tests that can never fail

Test the worst input a limit still allows

When you add a limit to stop malicious input, test the worst input the limit still allows, not only the one it now rejects.

01 · Before and afterThe pattern

Go
// before: proves the old attack is blocked
TestOrientation_HugeArray_IsSkipped()

// after: proves the worst accepted input stays cheap
func TestOrientation_WorstAllowed(t *testing.T) {
    img := buildEXIF(offsetsPerTag(2), entriesPerDir(65535)) // max under the cap
    start := time.Now(); _, _ = GetOrientation(img)
    require.Less(t, time.Since(start), time.Second)
}

02 · Run it on your appThe check

For each input limit you added for safety, do you have a test that feeds the largest input the limit accepts and measures the cost?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.