From: Mathias Gibbens Description: Fix test failure on 32bit architectures Forwarded: https://github.com/ovn-kubernetes/libovsdb/issues/374 diff --git a/modelgen/table.go b/modelgen/table.go index ede2a4a..2897f2a 100644 --- a/modelgen/table.go +++ b/modelgen/table.go @@ -428,13 +428,13 @@ func getAtomicValidations(atomicSchema *ovsdb.BaseType) []string { switch atomicSchema.Type { case ovsdb.TypeInteger: if minVal, err := atomicSchema.MinInteger(); err == nil { - defaultMinInteger := math.MinInt64 - if minVal != defaultMinInteger { + defaultMinInteger := int64(math.MinInt64) + if int64(minVal) != defaultMinInteger { validations = append(validations, fmt.Sprintf("min=%d", minVal)) } } if maxVal, err := atomicSchema.MaxInteger(); err == nil { - defaultMaxInteger := math.MaxInt64 + defaultMaxInteger := int64(math.MaxInt64) if maxVal != defaultMaxInteger { validations = append(validations, fmt.Sprintf("max=%d", maxVal)) } @@ -454,7 +454,7 @@ func getAtomicValidations(atomicSchema *ovsdb.BaseType) []string { } case ovsdb.TypeString: if maxVal, err := atomicSchema.MaxLength(); err == nil { - if maxVal != math.MaxInt32 && maxVal != math.MaxInt64 { + if maxVal != math.MaxInt32 && int64(maxVal) != int64(math.MaxInt64) { validations = append(validations, fmt.Sprintf("max=%d", maxVal)) } } diff --git a/ovsdb/schema.go b/ovsdb/schema.go index f59afa3..b015cd1 100644 --- a/ovsdb/schema.go +++ b/ovsdb/schema.go @@ -200,7 +200,7 @@ type BaseType struct { minReal *float64 maxReal *float64 minInteger *int - maxInteger *int + maxInteger *int64 minLength *int maxLength *int refTable *string @@ -251,14 +251,14 @@ func (b *BaseType) MinInteger() (int, error) { // MaxInteger returns the minimum integer value // RFC7047 specifies the minimum to be 2^63-1 -func (b *BaseType) MaxInteger() (int, error) { +func (b *BaseType) MaxInteger() (int64, error) { if b.Type != TypeInteger { return 0, fmt.Errorf("%s is not an integer", b.Type) } if b.maxInteger != nil { return *b.maxInteger, nil } - return int(math.Pow(2, 63)) - 1, nil + return int64(math.Pow(2, 63)) - 1, nil } // MinLength returns the minimum string length @@ -329,7 +329,7 @@ func (b *BaseType) UnmarshalJSON(data []byte) error { MinReal *float64 `json:"minReal,omitempty"` MaxReal *float64 `json:"maxReal,omitempty"` MinInteger *int `json:"minInteger,omitempty"` - MaxInteger *int `json:"maxInteger,omitempty"` + MaxInteger *int64 `json:"maxInteger,omitempty"` MinLength *int `json:"minLength,omitempty"` MaxLength *int `json:"maxLength,omitempty"` RefTable *string `json:"refTable,omitempty"` @@ -373,7 +373,7 @@ func (b BaseType) MarshalJSON() ([]byte, error) { MinReal *float64 `json:"minReal,omitempty"` MaxReal *float64 `json:"maxReal,omitempty"` MinInteger *int `json:"minInteger,omitempty"` - MaxInteger *int `json:"maxInteger,omitempty"` + MaxInteger *int64 `json:"maxInteger,omitempty"` MinLength *int `json:"minLength,omitempty"` MaxLength *int `json:"maxLength,omitempty"` RefTable *string `json:"refTable,omitempty"` diff --git a/ovsdb/schema_test.go b/ovsdb/schema_test.go index 8b22972..e7155c4 100644 --- a/ovsdb/schema_test.go +++ b/ovsdb/schema_test.go @@ -410,7 +410,7 @@ func TestTable(t *testing.T) { func TestBaseTypeMarshalUnmarshalJSON(t *testing.T) { datapath := "Datapath" zero := 0 - valMax := 4294967295 + valMax := int64(4294967295) strong := "strong" tests := []struct { name string @@ -678,7 +678,7 @@ func TestColumnSchemaMarshalUnmarshalJSON(t *testing.T) { func TestBaseTypeSimpleAtomic(t *testing.T) { b := BaseType{Type: TypeString} assert.True(t, b.simpleAtomic()) - valMax := 1024 + valMax := int64(1024) b1 := BaseType{Type: TypeInteger, maxInteger: &valMax} assert.False(t, b1.simpleAtomic()) } @@ -804,11 +804,11 @@ func TestBaseTypeMinInteger(t *testing.T) { } func TestBaseTypeMaxInteger(t *testing.T) { - value := 1024 + value := int64(1024) tests := []struct { name string bt *BaseType - want int + want int64 wantErr bool }{ { @@ -820,7 +820,7 @@ func TestBaseTypeMaxInteger(t *testing.T) { { "nil", &BaseType{Type: TypeInteger}, - int(math.Pow(2, 63)) - 1, + int64(math.Pow(2, 63)) - 1, false, }, {