-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an upgrade test for the new catalog
Currently this should be dormant and not executed. However its put in place to detect breaking changes in the future and show an example of how to do an upgrade test with integration tests structured like catalog v2.
- Loading branch information
Showing
5 changed files
with
118 additions
and
3 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
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
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
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
87 changes: 87 additions & 0 deletions
87
test/integration/consul-container/test/upgrade/catalog/catalog_test.go
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,87 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package catalog | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/hashicorp/consul/internal/catalog/catalogtest" | ||
"github.com/hashicorp/consul/proto-public/pbresource" | ||
libcluster "github.com/hashicorp/consul/test/integration/consul-container/libs/cluster" | ||
"github.com/hashicorp/consul/test/integration/consul-container/libs/topology" | ||
"github.com/hashicorp/consul/test/integration/consul-container/libs/utils" | ||
"github.com/hashicorp/go-version" | ||
) | ||
|
||
var minCatalogResourceVersion = version.Must(version.NewVersion("v1.16.0")) | ||
|
||
const ( | ||
versionUndetermined = ` | ||
Cannot determine the actual version the starting image represents. | ||
Scrutinze test failures to ensure that the starting version should | ||
actually be able to be used for creating the initial data set. | ||
` | ||
) | ||
|
||
func maybeSkipUpgradeTest(t *testing.T, minVersion *version.Version) { | ||
t.Helper() | ||
|
||
image := utils.DockerImage(utils.GetLatestImageName(), utils.LatestVersion) | ||
latestVersion, err := utils.DockerImageVersion(image) | ||
|
||
if latestVersion != nil && latestVersion.LessThan(minVersion) { | ||
t.Skipf("Upgrade test isn't applicable with version %q as the starting version", latestVersion.String()) | ||
} | ||
|
||
if err != nil || latestVersion == nil { | ||
t.Log(versionUndetermined) | ||
} | ||
} | ||
|
||
// Test upgrade a cluster of latest version to the target version and ensure that the catalog still | ||
// functions properly. Note | ||
func TestCatalogUpgrade(t *testing.T) { | ||
maybeSkipUpgradeTest(t, minCatalogResourceVersion) | ||
t.Parallel() | ||
|
||
const numServers = 1 | ||
buildOpts := &libcluster.BuildOptions{ | ||
ConsulImageName: utils.GetLatestImageName(), | ||
ConsulVersion: utils.LatestVersion, | ||
Datacenter: "dc1", | ||
InjectAutoEncryption: true, | ||
} | ||
|
||
cluster, _, _ := topology.NewCluster(t, &topology.ClusterConfig{ | ||
NumServers: 1, | ||
BuildOpts: buildOpts, | ||
ApplyDefaultProxySettings: true, | ||
Cmd: `-hcl=experiments=["resource-apis"]`, | ||
}) | ||
|
||
client := cluster.APIClient(0) | ||
|
||
libcluster.WaitForLeader(t, cluster, client) | ||
libcluster.WaitForMembers(t, client, numServers) | ||
|
||
leader, err := cluster.Leader() | ||
require.NoError(t, err) | ||
rscClient := pbresource.NewResourceServiceClient(leader.GetGRPCConn()) | ||
|
||
// Initialize some data | ||
catalogtest.PublishCatalogV1Alpha1IntegrationTestData(t, rscClient) | ||
|
||
// upgrade the cluster to the Target version | ||
t.Logf("initiating standard upgrade to version=%q", utils.TargetVersion) | ||
err = cluster.StandardUpgrade(t, context.Background(), utils.GetTargetImageName(), utils.TargetVersion) | ||
|
||
require.NoError(t, err) | ||
libcluster.WaitForLeader(t, cluster, client) | ||
libcluster.WaitForMembers(t, client, numServers) | ||
|
||
catalogtest.VerifyCatalogV1Alpha1IntegrationTestResults(t, rscClient) | ||
} |