diff --git a/.gitignore b/.gitignore index 400f9ea23a..f2c12b5ea0 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,6 @@ terraform-provider-github # Test exclusions !command/test-fixtures/**/*.tfstate !command/test-fixtures/**/.terraform/ - +examples/testing/** # do not commit secrets .env diff --git a/scripts/setup_env.sh b/scripts/setup_env.sh new file mode 100755 index 0000000000..434ed3143b --- /dev/null +++ b/scripts/setup_env.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +# Check for '-include-optional-env' parameter +INCLUDE_OPTIONAL=false +if [ "$1" == "-include-optional-env" ]; then + INCLUDE_OPTIONAL=true +fi + +# Check if launch.json already exists +if [ -f ".vscode/launch.json" ]; then + read -p "launch.json already exists. Overwrite? (y/n): " overwrite + if [[ $overwrite != "y" ]]; then + echo "Exiting without creating launch.json." + exit 1 + fi +fi + +# Prompt for required environment variables + +read -p "Enter GITHUB_TOKEN: " GITHUB_TOKEN +read -p "Enter GITHUB_OWNER: " GITHUB_OWNER +read -p "Enter GITHUB_ORGANIZATION (ex. octokit): " GITHUB_ORGANIZATION +read -p "Enter TF_TEST_FILE (ex. resource_github_team_members_test.go): " TF_TEST_FILE +read -p "Enter TF_TEST_FUNCTION (ex. TestAccGitHubRepositoryTopics): " TF_TEST_FUNCTION + +export GITHUB_TOKEN="$GITHUB_TOKEN" +export GITHUB_OWNER="$GITHUB_OWNER" +export GITHUB_ORGANIZATION="$GITHUB_ORGANIZATION" +export TF_TEST_FILE="$TF_TEST_FILE" +export TF_TEST_FUNCTION="$TF_TEST_FUNCTION" + +# Prompt for optional environment variables +if [ "$INCLUDE_OPTIONAL" = true ]; then + read -p "Enter GITHUB_TEST_USER: " GITHUB_TEST_USER + read -p "Enter GITHUB_TEST_COLLABORATOR: " GITHUB_TEST_COLLABORATOR + read -p "Enter GITHUB_TEST_COLLABORATOR_TOKEN: " GITHUB_TEST_COLLABORATOR_TOKEN + read -p "Enter GITHUB_TEMPLATE_REPOSITORY: " GITHUB_TEMPLATE_REPOSITORY + read -p "Enter GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID: " GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID + read -p "Enter TF_ACC: " TF_ACC + read -p "Enter APP_INSTALLATION_ID: " APP_INSTALLATION_ID + + # Export environment variables + export GITHUB_TEST_USER="$GITHUB_TEST_USER" + export GITHUB_TEST_COLLABORATOR="$GITHUB_TEST_COLLABORATOR" + export GITHUB_TEST_COLLABORATOR_TOKEN="$GITHUB_TEST_COLLABORATOR_TOKEN" + export GITHUB_TEMPLATE_REPOSITORY="$GITHUB_TEMPLATE_REPOSITORY" + export GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID="$GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID" + export GITHUB_ORGANIZATION="$GITHUB_ORGANIZATION" + export TF_ACC="$TF_ACC" + export TF_LOG="DEBUG" + export APP_INSTALLATION_ID="$APP_INSTALLATION_ID" +fi + +# Create the launch.json file +cat << EOF > .vscode/launch.json +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch test function", + "type": "go", + "request": "launch", + "mode": "test", + "program": "\${workspaceFolder}/github/\${env:TF_TEST_FILE}", + "args": [ + "-test.v", + "-test.run", + "^\${env:TF_TEST_FUNCTION}$" + ], + "env": { + "GITHUB_TEST_COLLABORATOR": "\${env:GITHUB_TEST_COLLABORATOR}", + "GITHUB_TEST_COLLABORATOR_TOKEN": "\${env:GITHUB_TEST_COLLABORATOR_TOKEN}", + "GITHUB_TEST_USER": "\${env:GITHUB_TEST_USER}", + "GITHUB_TOKEN": "\${env:GITHUB_TOKEN}", + "GITHUB_TEMPLATE_REPOSITORY": "\${env:GITHUB_TEMPLATE_REPOSITORY}", + "GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID": "\${env:GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID}", + "GITHUB_ORGANIZATION": "\${env:GITHUB_ORGANIZATION}", + "TF_CLI_CONFIG_FILE": "\${workspaceFolder}/examples/dev.tfrc", + "TF_ACC": "\${env:TF_ACC}", + "TF_LOG": "\${env:TF_LOG}", + "APP_INSTALLATION_ID": "\${env:APP_INSTALLATION_ID}" + } + }, + { + "name": "Attach to Process", + "type": "go", + "request": "attach", + "mode": "local", + "processId": "\${command:AskForProcessId}" + } + ] +} +EOF + +echo "launch.json has been created." \ No newline at end of file diff --git a/scripts/setup_testing.sh b/scripts/setup_testing.sh new file mode 100755 index 0000000000..d08edb84ab --- /dev/null +++ b/scripts/setup_testing.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Ask for the resource name +read -p "Enter the resource name to use in the test(i.e. issue_label for resource_github_issue_label): " resourceName + +# Define the directory and file path +DIR="examples/testing/${resourceName}" +FILE="${DIR}/main.tf" + +# Create the directory, if it doesn't already exist +mkdir -p "$DIR" + +# Create (or overwrite) the file and add the contents with the provided resource name +cat <"$FILE" +// Empty configuration +provider "github" { + //owner = "octokit" + //token = "ABC123" +} + +// Terraform global config for providers +terraform { + required_providers { + github = { + source = "integrations/github" + } + } + + // Example resource placeholder using provided resource name + // Documentation: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/${resourceName} + resource "${resourceName}" "test" { + + } +} +EOF + +echo "File ${FILE} has been created with the specified contents." \ No newline at end of file