test(spanner): compare data instead of struct
Compare the underlying Open Census row data, instead of the entire row
struct, with the expected value. This prevents the comparison from breaking
if new fields are added to the struct.
Fixes
@@ -57,31 +57,31 @@ func TestOCStats_SessionPool(t *testing.T) {
"OpenSessionCount",
OpenSessionCountView,
"open_session_count",
- "&{25}",
+ "25",
},
{
"MaxAllowedSessionsCount",
MaxAllowedSessionsCountView,
"max_allowed_sessions",
- "&{400}",
+ "400",
},
{
"MaxInUseSessionsCount",
MaxInUseSessionsCountView,
"max_in_use_sessions",
- "&{1}",
+ "1",
},
{
"AcquiredSessionsCount",
AcquiredSessionsCountView,
"num_acquired_sessions",
- "&{1}",
+ "1",
},
{
"ReleasedSessionsCount",
ReleasedSessionsCountView,
"num_released_sessions",
- "&{1}",
+ "1",
},
} {
t.Run(test.name, func(t *testing.T) {
@@ -123,7 +123,16 @@ func testSimpleMetric(t *testing.T, v *view.View, measure, value string) {
row := stat.Rows[0]
m := getTagMap(row.Tags)
checkCommonTags(t, m)
- if got, want := fmt.Sprintf("%v", row.Data), value; got != want {
+ var data string
+ switch row.Data.(type) {
+ default:
+ data = fmt.Sprintf("%v", row.Data)
+ case *view.CountData:
+ data = fmt.Sprintf("%v", row.Data.(*view.CountData).Value)
+ case *view.LastValueData:
+ data = fmt.Sprintf("%v", row.Data.(*view.LastValueData).Value)
+ }
+ if got, want := data, value; got != want {
t.Fatalf("Incorrect data: got %v, want %v", got, want)
}
case <-time.After(1 * time.Second):
@@ -179,17 +188,18 @@ func TestOCStats_SessionPool_SessionsCount(t *testing.T) {
// view.AggregationData does not have a way to extract the value. So
// we have to convert it to a string and then compare with expected
// values.
- got := fmt.Sprintf("%v", row.Data)
+ data := row.Data.(*view.LastValueData)
+ got := fmt.Sprintf("%v", data.Value)
var want string
switch m[tagKeyType] {
case "num_write_prepared_sessions":
- want = "&{20}"
+ want = "20"
case "num_read_sessions":
- want = "&{80}"
+ want = "80"
case "num_sessions_being_prepared":
- want = "&{0}"
+ want = "0"
case "num_in_use_sessions":
- want = "&{0}"
+ want = "0"
default:
t.Fatalf("Incorrect type: %v", m[tagKeyType])
}
@@ -242,7 +252,8 @@ func TestOCStats_SessionPool_GetSessionTimeoutsCount(t *testing.T) {
row := stat.Rows[0]
m := getTagMap(row.Tags)
checkCommonTags(t, m)
- if got, want := fmt.Sprintf("%v", row.Data), "&{1}"; got != want {
+ data := row.Data.(*view.CountData).Value
+ if got, want := fmt.Sprintf("%v", data), "1"; got != want {
t.Fatalf("Incorrect data: got %v, want %v", got, want)
}
case <-time.After(1 * time.Second):
