Skip to content

Commit

Permalink
Update README for how to set test configuration.
Browse files Browse the repository at this point in the history
* Update instructions in README for how to run set configuration for
  running tests.
* Skip ingress-https, ingress-iap, and ingress-asm-multi-backendconfig
  tests if expected variables are not set.
  • Loading branch information
sawsa307 committed Oct 24, 2023
1 parent 4c7cd32 commit 106aecd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ asm/
.crt
.key
.pem
certs/
certs/
30 changes: 30 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,42 @@ Make sure you have valid credentials for accessing GCP:
gcloud auth login
```

Set the project property in the core section by running:
```
gcloud config set project PROJECT_ID
```

Install jq by running:
```
sudo apt-get install jq
```

Make sure you are at the root directory of the repository.

```
cd gke-networking-recipes
```


Make sure to set ZONE and REGION environment variables before running tests. Resources will be deployed to the specified region and/or zone.
```
export ZONE=zone
export REGION=region
```

Tests for ingress-https, ingress-iap, and ingress-asm-multi-backendconfig will be skipped if the expected environment variables are not set.
To run ingress-https and ingress-iap test, you need a special project($DNS_PROJECT) that has a configured domain name with Cloud DNS, and make sure the current service account has role/dns_admin access to that project. Then, create a public DNS zone and export its zone name and DNS name.
```
export DNS_PROJECT=dns-project \
export DNS_ZONE=example-zone-name
export DNS_NAME=myzone.example.com
```

To run ingress-iap and ingress_asm-multi-backendconfig test, you need to have a support email that follows the requirement described in Programmatic OAuth clients: https://cloud.google.com/iap/docs/programmatic-oauth-clients.
```
export SUPPORT_EMAIL=support-email
```

To run a specific test, run the setup.sh, run-test.sh, and cleanup.sh in order in the recipe directory.

```
Expand Down
27 changes: 27 additions & 0 deletions test/recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func runRecipeTests(t *testing.T, parentPath string, fileNames []fs.DirEntry) {
if err := validateDir(path); err != nil {
t.Skipf("Skipping test %q: validateDir(%q) = %v", path, path, err)
}
if err := checkDependencies(path); err != nil {
t.Skipf("Skipping test %q: checkDependencies(%q) = %v", path, path, err)
}
runRecipeTest(t, path)
})
}
Expand Down Expand Up @@ -87,3 +90,27 @@ func validateDir(path string) error {
}
return nil
}

// checkDependencies checks if the dependencies are met for the given test.
func checkDependencies(testName string) error {
if testName == "ingress/single-cluster/ingress-asm-multi-backendconfig" {
return checkEnvs("SUPPORT_EMAIL")
}
if testName == "ingress/single-cluster/ingress-https" {
return checkEnvs("DNS_PROJECT", "DNS_ZONE", "DNS_NAME")
}
if testName == "ingress/single-cluster/ingress-iap" {
return checkEnvs("DNS_PROJECT", "DNS_ZONE", "DNS_NAME", "SUPPORT_EMAIL")
}
return nil
}

// checkEnvs checks if all specified environment variables are set.
func checkEnvs(envs ...string) error {
for _, env := range envs {
if _, found := os.LookupEnv(env); !found {
return fmt.Errorf("%q is not set. See test/README.md for more details", env)
}
}
return nil
}

0 comments on commit 106aecd

Please sign in to comment.