forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add acceptance tests instructions to Contributing (hashicorp#584)
* Update CONTRIBUTING.md with new acceptance tests info * Fix race condition in terraform templates
- Loading branch information
Showing
8 changed files
with
305 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package example | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/consul-helm/test/acceptance/framework" | ||
"github.com/hashicorp/consul-helm/test/acceptance/helpers" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestExample(t *testing.T) { | ||
// Get test configuration. | ||
cfg := suite.Config() | ||
|
||
// Get the default context. | ||
ctx := suite.Environment().DefaultContext(t) | ||
|
||
// Create Helm values for the Helm install. | ||
helmValues := map[string]string{ | ||
"exampleFeature.enabled": "true", | ||
} | ||
|
||
// Generate a random name for this test. | ||
releaseName := helpers.RandomName() | ||
|
||
// Create a new Consul cluster object. | ||
consulCluster := framework.NewHelmCluster(t, helmValues, ctx, cfg, releaseName) | ||
|
||
// Create the Consul cluster with Helm. | ||
consulCluster.Create(t) | ||
|
||
// Make test assertions. | ||
|
||
// To run kubectl commands, you need to get KubectlOptions from the test context. | ||
// There are a number of kubectl commands available in the helpers/kubectl.go file. | ||
// For example, to call 'kubectl apply' from the test write the following: | ||
helpers.KubectlApply(t, ctx.KubectlOptions(), "path/to/config") | ||
|
||
// Clean up any Kubernetes resources you have created | ||
helpers.Cleanup(t, cfg.NoCleanupOnFailure, func() { | ||
helpers.KubectlDelete(t, ctx.KubectlOptions(), "path/to/config") | ||
}) | ||
|
||
// Similarly, you can obtain Kubernetes client from your test context. | ||
// You can use it to, for example, read all services in a namespace: | ||
k8sClient := ctx.KubernetesClient(t) | ||
services, err := k8sClient.CoreV1().Services(ctx.KubectlOptions().Namespace).List(metav1.ListOptions{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, services.Items) | ||
|
||
// To make Consul API calls, you can get the Consul client from the consulCluster object, | ||
// indicating whether the client needs to be secure or not (i.e. whether TLS and ACLs are enabled on the Consul cluster): | ||
consulClient := consulCluster.SetupConsulClient(t, true) | ||
consulServices, _, err := consulClient.Catalog().Services(nil) | ||
require.NoError(t, err) | ||
require.NotNil(t, consulServices) | ||
} |
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,33 @@ | ||
package example | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/consul-helm/test/acceptance/framework" | ||
) | ||
|
||
var suite framework.Suite | ||
|
||
func TestMain(m *testing.M) { | ||
// First, uncomment the line below to create a new suite so that all flags are parsed. | ||
/* | ||
suite = framework.NewSuite(m) | ||
*/ | ||
|
||
// If the test suite needs to run only when certain test flags are passed, | ||
// you need to handle that in the TestMain function. | ||
// Uncomment and modify example code below if that is the case. | ||
/* | ||
if suite.Config().EnableExampleFeature { | ||
os.Exit(suite.Run()) | ||
} else { | ||
fmt.Println("Skipping example feature tests because -enable-example-feature is not set") | ||
os.Exit(0) | ||
} | ||
*/ | ||
|
||
// If the test suite should run in every case, uncomment the line below. | ||
/* | ||
os.Exit(suite.Run()) | ||
*/ | ||
} |
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
Oops, something went wrong.