@@ -2,10 +2,12 @@ package configparse
22
33import (
44 "errors"
5+ "fmt"
56 "net/http"
67 "net/url"
78 "os"
89 "path/filepath"
10+ "strconv"
911 "time"
1012
1113 "github.com/benchttp/engine/runner"
@@ -261,12 +263,16 @@ func newParsedConfig(uconf unmarshaledConfig) (parsedConfig, error) { //nolint:g
261263 if tests := uconf .Tests ; len (tests ) > 0 {
262264 cases := make ([]runner.TestCase , len (tests ))
263265 for i , t := range tests {
264- d , _ := parseOptionalDuration (* t .Target )
266+ source := runner .MetricsSource (* t .Source )
267+ target , err := parseMetricValue (source .Type (), * t .Target )
268+ if err != nil {
269+ return parsedConfig {}, err
270+ }
265271 cases [i ] = runner.TestCase {
266272 Name : * t .Name ,
267273 Source : runner .MetricsSource (* t .Source ),
268274 Predicate : runner .TestPredicate (* t .Predicate ),
269- Target : runner . MetricsValue ( d ) ,
275+ Target : target ,
270276 }
271277 }
272278 cfg .Tests = cases
@@ -309,3 +315,14 @@ func parseOptionalDuration(raw string) (time.Duration, error) {
309315 }
310316 return time .ParseDuration (raw )
311317}
318+
319+ func parseMetricValue (typ runner.MetricsType , in string ) (runner.MetricsValue , error ) {
320+ switch typ {
321+ case runner .MetricsTypeInt :
322+ return strconv .Atoi (in )
323+ case runner .MetricsTypeDuration :
324+ return time .ParseDuration (in )
325+ default :
326+ return nil , fmt .Errorf ("cannot parse metrics type: %v" , typ )
327+ }
328+ }
0 commit comments