Skip to content

Commit

Permalink
Add type check to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth committed Jun 9, 2023
1 parent 28205a8 commit 03d0e3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/ottl/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (g StandardStringLikeGetter[K]) Get(ctx context.Context, tCtx K) (*string,
default:
result, err = jsoniter.MarshalToString(v)
if err != nil {
return nil, fmt.Errorf("unsupported type: %T", v)
return nil, TypeError(fmt.Sprintf("unsupported type: %T", v))
}
}
return &result, nil
Expand Down Expand Up @@ -391,10 +391,10 @@ func (g StandardFloatLikeGetter[K]) Get(ctx context.Context, tCtx K) (*float64,
result = float64(0)
}
default:
return nil, fmt.Errorf("unsupported value type: %v", v.Type())
return nil, TypeError(fmt.Sprintf("unsupported value type: %v", v.Type()))
}
default:
return nil, fmt.Errorf("unsupported type: %T", v)
return nil, TypeError(fmt.Sprintf("unsupported type: %T", v))
}
return &result, nil
}
Expand Down Expand Up @@ -455,10 +455,10 @@ func (g StandardIntLikeGetter[K]) Get(ctx context.Context, tCtx K) (*int64, erro
result = int64(0)
}
default:
return nil, fmt.Errorf("unsupported value type: %v", v.Type())
return nil, TypeError(fmt.Sprintf("unsupported value type: %v", v.Type()))
}
default:
return nil, fmt.Errorf("unsupported type: %T", v)
return nil, TypeError(fmt.Sprintf("unsupported type: %T", v))
}
return &result, nil
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/ottl/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ func Test_StandardStringGetter(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tt.want, val)
} else {
assert.IsType(t, TypeError(""), err)
assert.EqualError(t, err, tt.expectedErrorMsg)
}
})
Expand Down Expand Up @@ -802,6 +803,7 @@ func Test_StandardStringLikeGetter(t *testing.T) {
assert.Equal(t, tt.want, *val)
}
} else {
assert.IsType(t, TypeError(""), err)
assert.EqualError(t, err, tt.expectedErrorMsg)
}
})
Expand Down Expand Up @@ -865,6 +867,7 @@ func Test_StandardFloatGetter(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tt.want, val)
} else {
assert.IsType(t, TypeError(""), err)
assert.EqualError(t, err, tt.expectedErrorMsg)
}
})
Expand Down Expand Up @@ -1028,6 +1031,7 @@ func Test_StandardFloatLikeGetter(t *testing.T) {
assert.Equal(t, tt.want, *val)
}
} else {
assert.IsType(t, TypeError(""), err)
assert.EqualError(t, err, tt.expectedErrorMsg)
}
})
Expand Down Expand Up @@ -1091,6 +1095,7 @@ func Test_StandardIntGetter(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tt.want, val)
} else {
assert.IsType(t, TypeError(""), err)
assert.EqualError(t, err, tt.expectedErrorMsg)
}
})
Expand Down Expand Up @@ -1254,6 +1259,7 @@ func Test_StandardIntLikeGetter(t *testing.T) {
assert.Equal(t, tt.want, *val)
}
} else {
assert.IsType(t, TypeError(""), err)
assert.EqualError(t, err, tt.expectedErrorMsg)
}
})
Expand Down Expand Up @@ -1327,6 +1333,7 @@ func Test_StandardPMapGetter(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tt.want, val)
} else {
assert.IsType(t, TypeError(""), err)
assert.EqualError(t, err, tt.expectedErrorMsg)
}
})
Expand Down

0 comments on commit 03d0e3a

Please sign in to comment.