Skip to content

Commit

Permalink
Fix examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
korenyoni committed Oct 17, 2023
1 parent ab5847e commit 2cb11c1
Show file tree
Hide file tree
Showing 45 changed files with 1,019 additions and 142 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ tests/

.idea
**/*.lock.hcl
**/*.backup
**/*.backup

.DS_Store
27 changes: 25 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ HOSTNAME=codefresh.io
PKG_NAME=codefresh
NAMESPACE=app
BINARY=terraform-provider-${PKG_NAME}
OS_ARCH=darwin_amd64
OS_ARCH=$$(go env GOOS)_$$(go env GOARCH)
TFPLUGINDOCS_VERSION=v0.14.1

default: build
Expand All @@ -22,13 +22,36 @@ build: fmtcheck
install: build
mv ${BINARY} $(HOME)/go/bin/

equivalence: build
@echo "==> Preparing equivalence tests"
mkdir -p testing/equivalence/.plugins/registry.terraform.io/codefresh-io/codefresh/0.6.0/${OS_ARCH}/
cp terraform-provider-codefresh testing/equivalence/.plugins/registry.terraform.io/codefresh-io/codefresh/0.6.0/${OS_ARCH}/

cd testing/equivalence;\
./update-test-cases.sh;\

@echo "==> Running equivalence tests for terraform"
cd testing/equivalence;\
equivalence-testing update --binary=$$(which terraform) --goldens=results/terraform --tests=test_cases --rewrites=rewrites.jsonc

@echo "==> Running equivalence tests for opentofu"
cd testing/equivalence;\
equivalence-testing update --binary=$$(which tofu) --goldens=results/opentofu --tests=test_cases --rewrites=rewrites.jsonc
fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w $(GOFMT_FILES)

fmtcheck: SHELL:=/bin/bash
fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
@echo "==> Checking that code complies with gofmt requirements..."

@gofmt_files=$$(find . -name '*.go' | grep -v vendor | xargs gofmt -l -s); \
if [[ -n $${gofmt_files} ]]; then\
echo 'gofmt needs running on the following files:';\
echo "$${gofmt_files}";\
echo "You can use the command: \`make fmt\` to reformat code.";\
exit 1;\
fi;
lint:
@echo "==> Checking source code against linters..."
golangci-lint run ./...
Expand Down
2 changes: 1 addition & 1 deletion codefresh/internal/schemautil/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ func (o *ValidationOptions) setSummary(summary string) *ValidationOptions {
func (o *ValidationOptions) setDetailFormat(detailFormat string) *ValidationOptions {
o.detailFormat = detailFormat
return o
}
}
4 changes: 2 additions & 2 deletions codefresh/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ func TestAccCodefreshPipeline_CronTriggersInvalid(t *testing.T) {
var pipeline cfclient.Pipeline

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCodefreshPipelineBasicConfigCronTriggers(
Expand Down
13 changes: 6 additions & 7 deletions codefresh/resource_step_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package codefresh

import (
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
Expand Down Expand Up @@ -48,8 +47,8 @@ func TestCleanUpStepFromTransientValues(t *testing.T) {
}

func TestNormalizeYamlStringStepTypes(t *testing.T) {
testFile := "../test_data/step_types/testStepWithRuntimeData.yaml"
yamlString, err := ioutil.ReadFile(testFile)
testFile := "../testing/fixtures/testStepWithRuntimeData.yaml"
yamlString, err := os.ReadFile(testFile)
if err != nil {
t.Errorf("Unable to open test file %s. Err: #%v ", testFile, err)
}
Expand Down Expand Up @@ -84,8 +83,8 @@ func TestSortVersions(t *testing.T) {
}

func TestExtractSteps(t *testing.T) {
testFile := "../test_data/step_types/testStepTypesOrder.yaml"
yamlString, err := ioutil.ReadFile(testFile)
testFile := "../testing/fixtures/testStepTypesOrder.yaml"
yamlString, err := os.ReadFile(testFile)
if err != nil {
t.Errorf("Unable to read file %s", testFile)
}
Expand All @@ -112,11 +111,11 @@ func TestAccCodefreshStepTypes(t *testing.T) {
}
name := accountName + "/" + stepTypesNamePrefix + acctest.RandString(10)
resourceName := "codefresh_step_types.test"
contentStepsV1, err := ioutil.ReadFile("../test_data/step_types/testSteps.yaml")
contentStepsV1, err := os.ReadFile("../testing/fixtures/testSteps.yaml")
if err != nil {
log.Fatal(err)
}
contentStepsV2, err := ioutil.ReadFile("../test_data/step_types/testStepsTemplate.yaml")
contentStepsV2, err := os.ReadFile("../testing/fixtures/testStepsTemplate.yaml")
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 0 additions & 4 deletions examples/abac_rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
data "codefresh_team" "admins" {
name = "admins"
}

data "codefresh_team" "users" {
name = "users"
}
Expand Down
5 changes: 0 additions & 5 deletions examples/abac_rules/provider.tf

This file was deleted.

3 changes: 0 additions & 3 deletions examples/abac_rules/terraform.tfvars

This file was deleted.

12 changes: 0 additions & 12 deletions examples/abac_rules/vars.tf

This file was deleted.

3 changes: 0 additions & 3 deletions examples/accounts_users/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
api_url = "https://my-codefresh.example.com/api"
token = "cfAdmin-token"

default_idps = {
local = {
display_name = "local"
Expand Down
2 changes: 0 additions & 2 deletions examples/accounts_users/vars.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
variable "api_url" {}

variable "default_acccount_limits" {
type = map(any)
default = {
Expand Down
4 changes: 0 additions & 4 deletions examples/permissions/provider.tf

This file was deleted.

1 change: 0 additions & 1 deletion examples/permissions/terraform.tfvars

This file was deleted.

8 changes: 0 additions & 8 deletions examples/permissions/vars.tf

This file was deleted.

5 changes: 0 additions & 5 deletions examples/pipelines/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
provider "codefresh" {
api_url = var.api_url
token = var.token
}

resource "codefresh_project" "test" {
name = "myproject"

Expand Down
2 changes: 0 additions & 2 deletions examples/pipelines/terraform.tfvars

This file was deleted.

8 changes: 0 additions & 8 deletions examples/pipelines/vars.tf

This file was deleted.

15 changes: 0 additions & 15 deletions examples/registries/main.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@

variable "api_url" {
type = string
}

variable "token" {
type = string
default = ""
}

variable "test_password" {
type = string
default = ""
}

provider "codefresh" {
api_url = var.api_url
token = var.token
}

resource "codefresh_registry" "acr" {
name = "acr"
default = true
Expand Down
3 changes: 0 additions & 3 deletions examples/registries/terraform.tfvars

This file was deleted.

13 changes: 0 additions & 13 deletions examples/storage_integration/provider.tf

This file was deleted.

8 changes: 0 additions & 8 deletions examples/storage_integration/vars.tf

This file was deleted.

13 changes: 0 additions & 13 deletions examples/teams/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
variable "api_url" {
type = string
}

variable "token" {
type = string
default = ""
}
provider "codefresh" {
api_url = var.api_url
token = var.token
}

variable "teams" {
type = map(any)
}
Expand Down
3 changes: 0 additions & 3 deletions examples/teams/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
api_url = "https://my-codefresh.example.com/api"
token = ""

teams = {
developers = ["user1", "user3"]
managers = ["user3", "user2"]
Expand Down
7 changes: 0 additions & 7 deletions examples/triggers/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
provider "codefresh" {
api_url = var.api_url
token = var.token
}

module "pipeline" {
source = "../pipelines"
api_url = var.api_url
token = var.token
}

resource "codefresh_pipeline_cron_trigger" "default" {
Expand Down
2 changes: 0 additions & 2 deletions examples/triggers/terraform.tfvars

This file was deleted.

8 changes: 0 additions & 8 deletions examples/triggers/vars.tf

This file was deleted.

15 changes: 15 additions & 0 deletions testing/equivalence/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Equivalence Tests

This directory contains equivalence tests for the provider.

See: https://github.com/opentofu/equivalence-testing

## Updating Equivalence Test Cases

When additional examples are added to [examples/](../../../examples), the equivalence test cases should be updated as well.

```bash
$ ./update-test-cases.sh
```

Then,
22 changes: 22 additions & 0 deletions testing/equivalence/compare-results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

source $(realpath $(dirname $0))/lib.sh

for i in $(find $(realpath $(dirname $0))/results/terraform -mindepth 1 -not -path '**/*/.*' -type d); do
test_case_name=$(basename ${i})
print_style "Test case "
print_style "${test_case_name}" "info"
print_style ":\n"
for f in $(find ${i} -type f); do
print_style " * comparing "
print_style "results/terraform/$(basename ${f})" "info"
print_style " and "
print_style "results/opentofu/$(basename ${f})" "info"
print_style ": "
diff \
$(realpath $(dirname $0))/results/terraform/$(basename ${i})/$(basename ${f}) \
$(realpath $(dirname $0))/results/opentofu/$(basename ${i})/$(basename ${f}) \
|| print_style "FAILED\n" "danger" \
&& print_style "PASS\n" "success"
done
done
22 changes: 22 additions & 0 deletions testing/equivalence/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# prints colored text
print_style () {

if [ "$2" == "info" ] ; then
COLOR="96m";
elif [ "$2" == "success" ] ; then
COLOR="92m";
elif [ "$2" == "warning" ] ; then
COLOR="93m";
elif [ "$2" == "danger" ] ; then
COLOR="91m";
else #default color
COLOR="0m";
fi

STARTCOLOR="\e[$COLOR";
ENDCOLOR="\e[0m";

printf "$STARTCOLOR%b$ENDCOLOR" "$1";
}
Loading

0 comments on commit 2cb11c1

Please sign in to comment.