FuzzValidateTemperatureParam fuzz tests that ValidateTemperatureParam: 1. Never panics on any string input. 2. Rejects NaN and infinite values. 3. Accepts only finite values in [0.0, 2.0]. To run: go test -v -fuzz=FuzzValidateTemperatureParam -fuzztime=30s ./pkg/workflow
(f *testing.F)
| 99 | // |
| 100 | // go test -v -fuzz=FuzzValidateTemperatureParam -fuzztime=30s ./pkg/workflow |
| 101 | func FuzzValidateTemperatureParam(f *testing.F) { |
| 102 | // Valid values. |
| 103 | f.Add("0.0") |
| 104 | f.Add("0.7") |
| 105 | f.Add("1.0") |
| 106 | f.Add("2.0") |
| 107 | f.Add("0") |
| 108 | f.Add("2") |
| 109 | f.Add("1.5") |
| 110 | // Boundary violations. |
| 111 | f.Add("-0.1") |
| 112 | f.Add("2.1") |
| 113 | f.Add("3.0") |
| 114 | // Special float strings accepted by strconv.ParseFloat but not by the spec. |
| 115 | f.Add("NaN") |
| 116 | f.Add("nan") |
| 117 | f.Add("+Inf") |
| 118 | f.Add("-Inf") |
| 119 | f.Add("Inf") |
| 120 | f.Add("inf") |
| 121 | // Non-numeric strings. |
| 122 | f.Add("") |
| 123 | f.Add("abc") |
| 124 | f.Add("1.0a") |
| 125 | f.Add("1,0") |
| 126 | |
| 127 | f.Fuzz(func(t *testing.T, input string) { |
| 128 | // Must never panic. |
| 129 | err := ValidateTemperatureParam(input) |
| 130 | |
| 131 | if err == nil { |
| 132 | // If accepted, the value must be a finite float in [0.0, 2.0]. |
| 133 | f64, parseErr := strconv.ParseFloat(input, 64) |
| 134 | if parseErr != nil { |
| 135 | t.Errorf("ValidateTemperatureParam(%q): accepted value that cannot be re-parsed as float64", input) |
| 136 | return |
| 137 | } |
| 138 | if math.IsNaN(f64) || math.IsInf(f64, 0) { |
| 139 | t.Errorf("ValidateTemperatureParam(%q): accepted non-finite value", input) |
| 140 | } |
| 141 | if f64 < 0.0 || f64 > 2.0 { |
| 142 | t.Errorf("ValidateTemperatureParam(%q): accepted out-of-range value %v", input, f64) |
| 143 | } |
| 144 | } |
| 145 | }) |
| 146 | } |
nothing calls this directly
no test coverage detected