Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run integration tests describe at CONTRIBUTING.md #501

Closed
skratochvil opened this issue Sep 26, 2023 · 2 comments · Fixed by #569
Closed

Can't run integration tests describe at CONTRIBUTING.md #501

skratochvil opened this issue Sep 26, 2023 · 2 comments · Fixed by #569

Comments

@skratochvil
Copy link
Contributor

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.

@msampathkumar msampathkumar self-assigned this Sep 28, 2023
@msampathkumar msampathkumar removed their assignment Nov 29, 2023
@glasnt
Copy link
Contributor

glasnt commented Jan 17, 2024

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.

@glasnt
Copy link
Contributor

glasnt commented Jan 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants
@glasnt @msampathkumar @skratochvil and others