Can't run integration tests describe at CONTRIBUTING.md
skratochvil opened this issue · comments
TL;DR
When I try to run the integration tests described at https://github.com/terraform-google-modules/terraform-docs-samples/blob/main/test/setup/main.tf, the output says the following:
testing: warning: no tests to run
PASS
So it doesn't seem like the tests are running.
Expected behavior
I expected to see something about a test pasing.
Observed behavior
The output from make -s docker_test_sample SAMPLE=networkconnectivity_create_service_connection_policy
contains the following:
testing: warning: no tests to run
PASS
Terraform Configuration
/**
* Copyright 2023 Google LLC
*
* 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.
*/
# [START networkconnectivity_create_service_connection_policy]
# Create a VPC network
resource "google_compute_network" "default" {
name = "consumer-network"
auto_create_subnetworks = false
}
# Create a subnetwork
resource "google_compute_subnetwork" "default" {
name = "consumer-subnet"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
}
# Create a service connection policy
resource "google_network_connectivity_service_connection_policy" "default" {
name = "my-service-connection-policy"
location = "us-central1"
service_class = "gcp-memorystore-redis"
description = "Description"
network = google_compute_network.default.id
psc_config {
subnetworks = [google_compute_subnetwork.default.id]
limit = 2
}
}
# [END networkconnectivity_create_service_connection_policy]
Terraform Version
Terraform v1.5.7
on linux_amd64
Additional information
Please let me know if you'd like to provide output from make docker_test_prepare
or make -s docker_test_sample SAMPLE=${SAMPLE_NAME}
. The content is too long to post here.
The CONTRIBUTING docs aren't clear what the value of SAMPLE
should be, but it's not the region tag (as denoted on # [START
and # [END
lines).
Looking at the build logs, it looks like the name of the test is the name of the folder that contains the main.tf
. In this case, this sample ended up being added in #500 (at a guess) as network_connectivity/service_connectivity_automation/service_connection_policies/main.tf
, so the test name is service_connection_policies
(in so far that it looks like this test name is running the code in that folder, as identified by unique resources/names/attributes.
I am trying to parse the sample_test.go
and (potentially) inherited code in CFT to confirm this logic is correct before updating CONTRIBUTING.md to clarify.
walkTerraformDirs
uses the filepath.Dir
for any folders with .tf files. filepath.Dir
"returns all but the last element of path, typically the path's directory.".
Then, TestSamples
uses the filepath.Base
of those values, where filepath.Base
"returns the last element of path".
Simple reproduction of logic (go playground):
package main
import (
"fmt"
"path/filepath"
)
func main() {
var myPath = "/Users/myname/git/terraform-docs-sample/run/add_tags/main.tf"
fmt.Printf("Input path: \n\t%s\n", myPath)
fmt.Printf("filepath.Dir: \n\t%s\n", filepath.Dir(myPath))
fmt.Printf("filepath.Base of filepath.Dir: \n\t%s\n", filepath.Base(filepath.Dir(myPath)))
}
Input path:
/Users/myname/git/terraform-docs-sample/run/add_tags/main.tf
filepath.Dir:
/Users/myname/git/terraform-docs-sample/run/add_tags
filepath.Base of filepath.Dir:
add_tags