-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package monkit | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestStatSourceFromStruct(t *testing.T) { | ||
type SubStruct struct { | ||
SubBool bool | ||
SubFloat float64 | ||
SubInt int64 | ||
Ignored float64 `monkit:"ignore"` | ||
} | ||
|
||
result := Collect(StatSourceFromStruct(NewSeriesKey("struct"), | ||
struct { | ||
SomeBool bool | ||
SomeFloat float64 | ||
SomeInt int64 | ||
Ignored float64 `monkit:"ignore"` | ||
Sub SubStruct | ||
Skip struct { | ||
Nope int64 | ||
} `monkit:"whatever,ignore"` | ||
}{ | ||
SomeInt: 5, | ||
SomeBool: true, | ||
Sub: SubStruct{ | ||
SubFloat: 3.2, | ||
}, | ||
}, | ||
)) | ||
|
||
if !reflect.DeepEqual(result, map[string]float64{ | ||
"struct SomeBool": 1, | ||
"struct SomeFloat": 0, | ||
"struct SomeInt": 5, | ||
"struct Sub.SubBool": 0, | ||
"struct Sub.SubFloat": 3.2, | ||
"struct Sub.SubInt": 0, | ||
}) { | ||
t.Fatal("unexpected result", result) | ||
} | ||
} |