1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
From: Mathias Gibbens <gibmat@debian.org>
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,
},
{
|