-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: unit tests for InstallConfig validation
- Loading branch information
Showing
10 changed files
with
879 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
|
||
"github.com/openshift/installer/pkg/types/aws" | ||
) | ||
|
||
func TestValidateMachinePool(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
pool *aws.MachinePool | ||
valid bool | ||
}{ | ||
{ | ||
name: "empty", | ||
pool: &aws.MachinePool{}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "valid iops", | ||
pool: &aws.MachinePool{ | ||
EC2RootVolume: aws.EC2RootVolume{ | ||
IOPS: 10, | ||
}, | ||
}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid iops", | ||
pool: &aws.MachinePool{ | ||
EC2RootVolume: aws.EC2RootVolume{ | ||
IOPS: -10, | ||
}, | ||
}, | ||
valid: false, | ||
}, | ||
{ | ||
name: "valid size", | ||
pool: &aws.MachinePool{ | ||
EC2RootVolume: aws.EC2RootVolume{ | ||
Size: 10, | ||
}, | ||
}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid size", | ||
pool: &aws.MachinePool{ | ||
EC2RootVolume: aws.EC2RootVolume{ | ||
Size: -10, | ||
}, | ||
}, | ||
valid: false, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := ValidateMachinePool(tc.pool, field.NewPath("test-path")).ToAggregate() | ||
if tc.valid { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
|
||
"github.com/openshift/installer/pkg/ipnet" | ||
"github.com/openshift/installer/pkg/types/aws" | ||
) | ||
|
||
func TestValidatePlatform(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
platform *aws.Platform | ||
valid bool | ||
}{ | ||
{ | ||
name: "minimal", | ||
platform: &aws.Platform{ | ||
Region: "us-east-1", | ||
}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid region", | ||
platform: &aws.Platform{ | ||
Region: "bad-region", | ||
}, | ||
valid: false, | ||
}, | ||
{ | ||
name: "valid machine pool", | ||
platform: &aws.Platform{ | ||
Region: "us-east-1", | ||
DefaultMachinePlatform: &aws.MachinePool{}, | ||
}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid machine pool", | ||
platform: &aws.Platform{ | ||
Region: "us-east-1", | ||
DefaultMachinePlatform: &aws.MachinePool{ | ||
EC2RootVolume: aws.EC2RootVolume{ | ||
IOPS: -10, | ||
}, | ||
}, | ||
}, | ||
valid: false, | ||
}, | ||
{ | ||
name: "valid CIDR", | ||
platform: &aws.Platform{ | ||
Region: "us-east-1", | ||
VPCCIDRBlock: ipnet.MustParseCIDR("192.168.0.0/16"), | ||
}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid CIDR", | ||
platform: &aws.Platform{ | ||
Region: "us-east-1", | ||
VPCCIDRBlock: ipnet.MustParseCIDR("0.0.0.0/16"), | ||
}, | ||
valid: false, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := ValidatePlatform(tc.platform, field.NewPath("test-path")).ToAggregate() | ||
if tc.valid { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
|
||
"github.com/openshift/installer/pkg/types/libvirt" | ||
) | ||
|
||
func TestValidateMachinePool(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
pool *libvirt.MachinePool | ||
valid bool | ||
}{ | ||
{ | ||
name: "empty", | ||
pool: &libvirt.MachinePool{}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "valid image", | ||
pool: &libvirt.MachinePool{ | ||
Image: "https://example.com/rhcos-qemu.qcow2", | ||
}, | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid image", | ||
pool: &libvirt.MachinePool{ | ||
Image: "bad-image", | ||
}, | ||
valid: false, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := ValidateMachinePool(tc.pool, field.NewPath("test-path")).ToAggregate() | ||
if tc.valid { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
|
||
"github.com/openshift/installer/pkg/ipnet" | ||
"github.com/openshift/installer/pkg/types/libvirt" | ||
) | ||
|
||
func validPlatform() *libvirt.Platform { | ||
return &libvirt.Platform{ | ||
URI: "qemu+tcp://192.168.122.1/system", | ||
Network: libvirt.Network{ | ||
IfName: "tt0", | ||
IPRange: *ipnet.MustParseCIDR("10.0.0.0/16"), | ||
}, | ||
} | ||
} | ||
|
||
func TestValidatePlatform(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
platform *libvirt.Platform | ||
valid bool | ||
}{ | ||
{ | ||
name: "minimal", | ||
platform: validPlatform(), | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid uri", | ||
platform: func() *libvirt.Platform { | ||
p := validPlatform() | ||
p.URI = "bad-uri" | ||
return p | ||
}(), | ||
valid: false, | ||
}, | ||
{ | ||
name: "missing interface name", | ||
platform: func() *libvirt.Platform { | ||
p := validPlatform() | ||
p.Network.IfName = "" | ||
return p | ||
}(), | ||
valid: false, | ||
}, | ||
{ | ||
name: "missing ip range", | ||
platform: func() *libvirt.Platform { | ||
p := validPlatform() | ||
p.Network.IPRange = ipnet.IPNet{} | ||
return p | ||
}(), | ||
valid: false, | ||
}, | ||
{ | ||
name: "valid machine pool", | ||
platform: func() *libvirt.Platform { | ||
p := validPlatform() | ||
p.DefaultMachinePlatform = &libvirt.MachinePool{} | ||
return p | ||
}(), | ||
valid: true, | ||
}, | ||
{ | ||
name: "invalid machine pool", | ||
platform: func() *libvirt.Platform { | ||
p := validPlatform() | ||
p.DefaultMachinePlatform = &libvirt.MachinePool{ | ||
Image: "bad-image", | ||
} | ||
return p | ||
}(), | ||
valid: false, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := ValidatePlatform(tc.platform, field.NewPath("test-path")).ToAggregate() | ||
if tc.valid { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
|
||
"github.com/openshift/installer/pkg/types/openstack" | ||
) | ||
|
||
func TestValidateMachinePool(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
pool *openstack.MachinePool | ||
valid bool | ||
}{ | ||
{ | ||
name: "empty", | ||
pool: &openstack.MachinePool{}, | ||
valid: true, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := ValidateMachinePool(tc.pool, field.NewPath("test-path")).ToAggregate() | ||
if tc.valid { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.