Download this file
| 1 | package status |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "reflect" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestScanForNumericLeaksFindsNestedFixtureFractions(t *testing.T) { |
| 10 | var decoded interface{} |
| 11 | if err := json.Unmarshal([]byte(`{"object":{"ratio":0.95},"list":[{"ratio":0.73}]}`), &decoded); err != nil { |
| 12 | t.Fatal(err) |
| 13 | } |
| 14 | if got, want := scanForNumericLeaks(decoded, dryRunFractionNeedles), []string{"0.73", "0.95"}; !reflect.DeepEqual(got, want) { |
| 15 | t.Fatalf("numeric leaks = %v, want %v", got, want) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func TestScanForNumericLeaksIgnoresTimestampText(t *testing.T) { |
| 20 | var decoded interface{} |
| 21 | if err := json.Unmarshal([]byte(`{"generated_at":"2026-09-09T16:15:10.950730Z"}`), &decoded); err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if got := scanForNumericLeaks(decoded, dryRunFractionNeedles); len(got) != 0 { |
| 25 | t.Fatalf("timestamp text reported as numeric leak: %v", got) |
| 26 | } |
| 27 | } |
| 28 | |