Move version code to separate files
This commit is contained in:
17
internal/provider/controller_versions.go
Normal file
17
internal/provider/controller_versions.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/go-version"
|
||||
)
|
||||
|
||||
var (
|
||||
controllerV5 = version.Must(version.NewVersion("5.0.0"))
|
||||
controllerV6 = version.Must(version.NewVersion("6.0.0"))
|
||||
|
||||
// https://community.ui.com/releases/UniFi-Network-Controller-6-1-61/62f1ad38-1ac5-430c-94b0-becbb8f71d7d
|
||||
controllerVersionWPA3 = version.Must(version.NewVersion("6.1.61"))
|
||||
)
|
||||
|
||||
func (c *client) ControllerVersion() *version.Version {
|
||||
return version.Must(version.NewVersion(c.c.Version()))
|
||||
}
|
||||
31
internal/provider/controller_versions_test.go
Normal file
31
internal/provider/controller_versions_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
)
|
||||
|
||||
func preCheckMinVersion(t *testing.T, min *version.Version) {
|
||||
v, err := version.NewVersion(testClient.Version())
|
||||
if err != nil {
|
||||
t.Fatalf("error parsing version: %s", err)
|
||||
}
|
||||
if v.LessThan(min) {
|
||||
t.Skipf("skipping test on controller version %q (need at least %q)", v, min)
|
||||
}
|
||||
}
|
||||
|
||||
func preCheckV6Only(t *testing.T) {
|
||||
preCheckMinVersion(t, controllerV6)
|
||||
}
|
||||
|
||||
func preCheckV5Only(t *testing.T) {
|
||||
v, err := version.NewVersion(testClient.Version())
|
||||
if err != nil {
|
||||
t.Fatalf("error parsing version: %s", err)
|
||||
}
|
||||
if v.GreaterThanOrEqual(controllerV6) {
|
||||
t.Skipf("skipping test on controller version %q", v)
|
||||
}
|
||||
}
|
||||
@@ -6,20 +6,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
)
|
||||
|
||||
var (
|
||||
controllerV5 = version.Must(version.NewVersion("5.0.0"))
|
||||
controllerV6 = version.Must(version.NewVersion("6.0.0"))
|
||||
|
||||
// https://community.ui.com/releases/UniFi-Network-Controller-6-1-61/62f1ad38-1ac5-430c-94b0-becbb8f71d7d
|
||||
controllerVersionWPA3 = version.Must(version.NewVersion("6.1.61"))
|
||||
)
|
||||
|
||||
func init() {
|
||||
schema.DescriptionKind = schema.StringMarkdown
|
||||
|
||||
@@ -226,7 +216,3 @@ type client struct {
|
||||
c unifiClient
|
||||
site string
|
||||
}
|
||||
|
||||
func (c *client) ControllerVersion() *version.Version {
|
||||
return version.Must(version.NewVersion(c.c.Version()))
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
|
||||
@@ -85,30 +84,6 @@ func preCheck(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func preCheckMinVersion(t *testing.T, min *version.Version) {
|
||||
v, err := version.NewVersion(testClient.Version())
|
||||
if err != nil {
|
||||
t.Fatalf("error parsing version: %s", err)
|
||||
}
|
||||
if v.LessThan(min) {
|
||||
t.Skipf("skipping test on controller version %q (need at least %q)", v, min)
|
||||
}
|
||||
}
|
||||
|
||||
func preCheckV6Only(t *testing.T) {
|
||||
preCheckMinVersion(t, controllerV6)
|
||||
}
|
||||
|
||||
func preCheckV5Only(t *testing.T) {
|
||||
v, err := version.NewVersion(testClient.Version())
|
||||
if err != nil {
|
||||
t.Fatalf("error parsing version: %s", err)
|
||||
}
|
||||
if v.GreaterThanOrEqual(controllerV6) {
|
||||
t.Skipf("skipping test on controller version %q", v)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
vlanMin = 2
|
||||
vlanMax = 4095
|
||||
|
||||
Reference in New Issue
Block a user