Skip to content

Commit

Permalink
Backport of test: add test helper to detect if the current build is e…
Browse files Browse the repository at this point in the history
…nterprise into release/1.17.x (#19612)

test: add test helper to detect if the current build is enterprise (#19201)

This can help conditionally change test behavior if the test is executing in enterprise without the need to split the test with build tags.

Co-authored-by: R.B. Boyer <[email protected]>
  • Loading branch information
hc-github-team-consul-core and rboyer authored Nov 13, 2023
1 parent 45f4294 commit b0d7faa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/catalog/internal/types/failover_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"google.golang.org/protobuf/proto"

"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/internal/resource"
"github.com/hashicorp/consul/internal/resource/resourcetest"
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"
"github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/consul/proto/private/prototest"
"github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/consul/version/versiontest"
)

func TestMutateFailoverPolicy(t *testing.T) {
Expand Down Expand Up @@ -749,7 +749,7 @@ func TestFailoverPolicyACLs(t *testing.T) {
})
}

isEnterprise := (structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty() == "default")
isEnterprise := versiontest.IsEnterprise()

serviceRead := func(partition, namespace, name string) string {
if isEnterprise {
Expand Down
4 changes: 2 additions & 2 deletions internal/mesh/internal/types/destination_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/durationpb"

"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/internal/resource"
"github.com/hashicorp/consul/internal/resource/resourcetest"
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1"
"github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/consul/proto/private/prototest"
"github.com/hashicorp/consul/sdk/testutil"
"github.com/hashicorp/consul/version/versiontest"
)

func TestValidateDestinationPolicy(t *testing.T) {
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestDestinationPolicyACLs(t *testing.T) {
})
}

isEnterprise := (structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty() == "default")
isEnterprise := versiontest.IsEnterprise()

serviceRead := func(partition, namespace, name string) string {
if isEnterprise {
Expand Down
4 changes: 2 additions & 2 deletions internal/mesh/internal/types/xroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/wrapperspb"

"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/internal/resource"
"github.com/hashicorp/consul/internal/resource/resourcetest"
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1"
"github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/consul/version/versiontest"
)

type xRouteParentRefMutateTestcase struct {
Expand Down Expand Up @@ -441,7 +441,7 @@ func testXRouteACLs[R XRouteData](t *testing.T, newRoute func(t *testing.T, pare
})
}

isEnterprise := (structs.NodeEnterpriseMetaInDefaultPartition().PartitionOrEmpty() == "default")
isEnterprise := versiontest.IsEnterprise()

serviceRead := func(partition, namespace, name string) string {
if isEnterprise {
Expand Down
13 changes: 13 additions & 0 deletions version/versiontest/versiontest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

package versiontest

import "github.com/hashicorp/consul/version"

// IsEnterprise returns true if the current build is a Consul Enterprise build.
//
// This should only be called from test code.
func IsEnterprise() bool {
return version.VersionMetadata == "ent"
}

0 comments on commit b0d7faa

Please sign in to comment.