-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Terraform and Helm tests with Terratest
Useful to check if Terraform configuration is valid and verify different variables used by helm templates.
- Loading branch information
Showing
4 changed files
with
782 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2020 Google LLC All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package test | ||
|
||
import ( | ||
"flag" | ||
"testing" | ||
"time" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var project string | ||
|
||
func TestTerraformGKEInstallConfig(t *testing.T) { | ||
t.Logf("Using project %s\n", project) | ||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "../../build/terraform/gke/", | ||
Vars: map[string]interface{}{ | ||
"project": project, | ||
"name": "terratest-cluster", | ||
"values_file": "", | ||
}, | ||
} | ||
|
||
defer destroy(t, terraformOptions) | ||
|
||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
output := terraform.Output(t, terraformOptions, "host") | ||
assert.Contains(t, output, "https://") | ||
} | ||
|
||
func destroy(t *testing.T, options *terraform.Options) { | ||
options.Targets = []string{"module.helm_agones.helm_release.agones"} | ||
terraform.Destroy(t, options) | ||
time.Sleep(30 * time.Second) | ||
options.Targets = []string{} | ||
terraform.Destroy(t, options) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
projectFlag := flag.String("project", "agones", "name of the proejct") | ||
flag.Parse() | ||
project = *projectFlag | ||
m.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/agones/agones/test/terraform | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/gruntwork-io/terratest v0.26.6 | ||
github.com/stretchr/testify v1.5.1 | ||
k8s.io/api v0.17.0 | ||
k8s.io/apiextensions-apiserver v0.15.7 | ||
) |
Oops, something went wrong.