-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/bosun: func to turn seconds (scalars) to duration string
- Loading branch information
1 parent
2acf8e5
commit 5621c96
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package expr | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/influxdata/influxdb/client" | ||
) | ||
|
||
type exprInOut struct { | ||
expr string | ||
out Results | ||
} | ||
|
||
func testExpression(eio exprInOut) error { | ||
e, err := New(eio.expr, builtins) | ||
if err != nil { | ||
return err | ||
} | ||
r, _, err := e.Execute(nil, nil, nil, nil, client.Config{}, nil, nil, time.Now(), 0, false, nil, nil, nil) | ||
if err != nil { | ||
return err | ||
} | ||
if _, err := eio.out.Equal(r); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func TestDuration(t *testing.T) { | ||
d := exprInOut{ | ||
`d("1h")`, | ||
Results{ | ||
Results: ResultSlice{ | ||
&Result{ | ||
Value: Scalar(3600), | ||
}, | ||
}, | ||
}, | ||
} | ||
err := testExpression(d) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func TestToDuration(t *testing.T) { | ||
d := exprInOut{ | ||
`tod(3600*2)`, | ||
Results{ | ||
Results: ResultSlice{ | ||
&Result{ | ||
Value: String("2h"), | ||
}, | ||
}, | ||
}, | ||
} | ||
err := testExpression(d) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
This file contains 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
This file contains 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