Skip to content

Commit

Permalink
Fix PF Int32 types being mistranslated to Floats (#2926)
Browse files Browse the repository at this point in the history
In the PF bridge, we would previously translate PF Int32 types as Float.
This PR adds explicit handling for it as well as tests.

fixes #2924
  • Loading branch information
VenelinMartinov authored Mar 3, 2025
1 parent 55d6d45 commit 871ecda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/pf/internal/schemashim/convert_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func convertType(typ pfattr.Type) (shim.ValueType, error) {
switch {
case is(tftypes.Bool):
return shim.TypeBool, nil
case typ.Equal(basetypes.Int32Type{}):
return shim.TypeInt, nil
case typ.Equal(basetypes.Int64Type{}):
// We special case int, since it is a stable type but not present on the wire.
return shim.TypeInt, nil
Expand Down
18 changes: 18 additions & 0 deletions pkg/pf/internal/schemashim/type_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,21 @@ func assertIsMapType(t *testing.T, shimmed shim.Schema) {
schema, isTypeSchema := shimmed.Elem().(*typeSchema)
assert.Truef(t, isTypeSchema, "expected shim.Elem() to be of type %T", *schema)
}

func TestInt32Type(t *testing.T) {
t.Parallel()
shimmed := &typeSchema{basetypes.Int32Type{}, nil}
assert.Equal(t, shim.TypeInt, shimmed.Type())
}

func TestInt64Type(t *testing.T) {
t.Parallel()
shimmed := &typeSchema{basetypes.Int64Type{}, nil}
assert.Equal(t, shim.TypeInt, shimmed.Type())
}

func TestNumberType(t *testing.T) {
t.Parallel()
shimmed := &typeSchema{basetypes.NumberType{}, nil}
assert.Equal(t, shim.TypeFloat, shimmed.Type())
}

0 comments on commit 871ecda

Please sign in to comment.