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

add GitHub Actions for e2e test #62

Merged
merged 25 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/e2e_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: E2E tests

on:
pull_request:
paths-ignore:
- "README.md"
- docs/**
- examples/**
branches:
- main

permissions:
contents: read

jobs:
e2e_test:
name: E2E tests
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: "go.mod"
cache: true
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3.1.1
- run: go mod download
- run: |
make testacc
env:
TROCCO_API_KEY: ${{ secrets.TROCCO_API_KEY }}
TROCCO_TEST_URL: https://trocco.io
1 change: 0 additions & 1 deletion internal/provider/connection_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestAccConnectionResource(t *testing.T) {
Config: providerConfig + `
resource "trocco_connection" "test" {
connection_type = "bigquery"

name = "test"
description = "The quick brown fox jumps over the lazy dog."
project_id = "test"
Expand Down
56 changes: 45 additions & 11 deletions internal/provider/job_definition_resource_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package provider

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -14,20 +13,57 @@ func TestAccJobDefinitionResource(t *testing.T) {
Steps: []resource.TestStep{
{
Config: providerConfig + `


resource "trocco_connection" "test_mysql" {
connection_type = "mysql"
name = "MySQL Example"
host = "db.example.com"
port = 65535
user_name = "root"
password = "password"
}
resource "trocco_connection" "test_bq" {
connection_type = "bigquery"
name = "BigQuery Example"
project_id = "example"
service_account_json_key = <<JSON
{
"type": "service_account",
"project_id": "example-project-id",
"private_key_id": "example-private-key-id",
"private_key":"-----BEGIN PRIVATE KEY-----\n..."
}
JSON
}
resource "trocco_team" "test" {
name = "test"
members = [
{
user_id = 10626
role = "team_admin"
},
]
}
resource "trocco_resource_group" "test" {
name = "test"
description = "test"
teams = [
{
team_id = trocco_team.test.id
role = "administrator"
},
]
}
resource "trocco_job_definition" "mysql_to_bigquery" {
name = "test job_definition"
description = "test description"
resource_enhancement = "large"
resource_group_id = 1
resource_group_id = trocco_resource_group.test.id
retry_limit = 1
is_runnable_concurrently = true
filter_columns = [
{
default = ""
format = "%Y"
json_expand_columns = []
json_expand_enabled = false
json_expand_keep_base_column = false
name = "id"
Expand All @@ -36,7 +72,6 @@ resource "trocco_job_definition" "mysql_to_bigquery" {
},
{
default = ""
json_expand_columns = []
json_expand_enabled = false
json_expand_keep_base_column = false
name = "name"
Expand All @@ -46,7 +81,6 @@ resource "trocco_job_definition" "mysql_to_bigquery" {
{
default = ""
format = ""
json_expand_columns = []
json_expand_enabled = false
json_expand_keep_base_column = false
name = "created_at"
Expand Down Expand Up @@ -182,7 +216,7 @@ resource "trocco_job_definition" "mysql_to_bigquery" {
type = "timestamp"
},
]
mysql_connection_id = 1
mysql_connection_id = trocco_connection.test_mysql.id
query = <<-EOT
select
*
Expand All @@ -204,9 +238,10 @@ resource "trocco_job_definition" "mysql_to_bigquery" {
read_timeout_sec = 300
send_timeout_sec = 300
retries = 2
bigquery_connection_id = 1
bigquery_connection_id = trocco_connection.test_bq.id
location = "us-west1"
bigquery_output_option_clustering_fields = []
bigquery_output_option_column_options = []
bigquery_output_option_merge_keys = []
}
}
Expand All @@ -217,7 +252,6 @@ resource "trocco_job_definition" "mysql_to_bigquery" {
resource.TestCheckResourceAttr("trocco_job_definition.mysql_to_bigquery", "name", "test job_definition"),
resource.TestCheckResourceAttr("trocco_job_definition.mysql_to_bigquery", "description", "test description"),
resource.TestCheckResourceAttr("trocco_job_definition.mysql_to_bigquery", "resource_enhancement", "large"),
resource.TestCheckResourceAttr("trocco_job_definition.mysql_to_bigquery", "resource_group_id", "1"),
resource.TestCheckResourceAttr("trocco_job_definition.mysql_to_bigquery", "retry_limit", "1"),
resource.TestCheckResourceAttr("trocco_job_definition.mysql_to_bigquery", "is_runnable_concurrently", "true"),
),
Expand All @@ -230,7 +264,7 @@ resource "trocco_job_definition" "mysql_to_bigquery" {
ImportStateIdFunc: func(s *terraform.State) (string, error) {
jobDefinitionId := s.RootModule().Resources["trocco_job_definition.mysql_to_bigquery"].Primary.ID

return fmt.Sprintf("job_definition,%s", jobDefinitionId), nil
return jobDefinitionId, nil
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/label_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestAccLabelResource(t *testing.T) {
},
{
Config: providerConfig + `
resource "trocco_label" "test" {
resource "trocco_label" "test_empty_description" {
name = "Updated Label, Second Time"
color = "#000000"
}
Expand All @@ -81,13 +81,13 @@ func TestAccLabelResource(t *testing.T) {
},
{
Config: providerConfig + `
resource "trocco_label" "test2" {
resource "trocco_label" "test_empty_description_test2" {
name = "Updated Label, Third Time"
color = "#000000"
description = ""
}
`,
Check: resource.TestCheckResourceAttr("trocco_label.test_empty_description", "description", ""),
Check: resource.TestCheckResourceAttr("trocco_label.test_empty_description_test2", "description", ""),
},
},
})
Expand Down
48 changes: 34 additions & 14 deletions internal/provider/resource_group_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ func TestAccResourceGroupResource(t *testing.T) {
// Create and Read testing
{
Config: providerConfig + `
resource "trocco_team" "team1" {
name = "test"
members = [
{
user_id = 10626
role = "team_admin"
}
]
}
resource "trocco_resource_group" "test" {
name = "test"
description = "test"
teams = [
{
team_id = 1
team_id = trocco_team.team1.id
role = "operator"
}
]
Expand All @@ -29,7 +38,6 @@ func TestAccResourceGroupResource(t *testing.T) {
resource.TestCheckResourceAttr("trocco_resource_group.test", "name", "test"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "description", "test"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.#", "1"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.0.team_id", "1"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.0.role", "operator"),
),
},
Expand All @@ -43,29 +51,31 @@ func TestAccResourceGroupResource(t *testing.T) {
// Update testing
{
Config: providerConfig + `
resource "trocco_team" "team1" {
name = "test1"
members = [
{
user_id = 10626
role = "team_admin"
}
]
}
resource "trocco_resource_group" "test" {
name = "updated"
description = "updated"
teams = [
{
team_id = 1
team_id = trocco_team.team1.id
role = "administrator"
},
{
team_id = 2
role = "operator"
}
]
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("trocco_resource_group.test", "name", "updated"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "description", "updated"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.#", "2"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.0.team_id", "1"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.#", "1"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.0.role", "administrator"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.1.team_id", "2"),
resource.TestCheckResourceAttr("trocco_resource_group.test", "teams.1.role", "operator"),
),
},
},
Expand Down Expand Up @@ -100,16 +110,26 @@ func TestAccResourceGroupDuplicateRoles(t *testing.T) {
Steps: []resource.TestStep{
{
Config: providerConfig + `
resource "trocco_team" "team1" {
name = "test"
description = "test"
members = [
{
user_id = 10626
role = "team_admin"
}
]
}
resource "trocco_resource_group" "test" {
name = "test"
description = "test"
teams = [
{ team_id = 1, role = "administrator" },
{ team_id = 1, role = "operator" },
{ team_id = trocco_team.team1.id, role = "administrator" },
{ team_id = trocco_team.team1.id, role = "operator" },
]
}
`,
ExpectError: regexp.MustCompile(`Team ID "1" is duplicated in the list.`),
ExpectError: regexp.MustCompile(`Team ID "<unknown>" is duplicated in the list.`),
},
},
})
Expand Down
10 changes: 4 additions & 6 deletions internal/provider/team_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAccTeamResource(t *testing.T) {
description = "test"
members = [
{
user_id = 1
user_id = 10626
role = "team_admin"
}
]
Expand All @@ -29,7 +29,6 @@ func TestAccTeamResource(t *testing.T) {
resource.TestCheckResourceAttr("trocco_team.test", "name", "test"),
resource.TestCheckResourceAttr("trocco_team.test", "description", "test"),
resource.TestCheckResourceAttr("trocco_team.test", "members.#", "1"),
resource.TestCheckResourceAttr("trocco_team.test", "members.0.user_id", "1"),
resource.TestCheckResourceAttr("trocco_team.test", "members.0.role", "team_admin"),
),
},
Expand All @@ -43,16 +42,17 @@ func TestAccTeamResource(t *testing.T) {
// Update testing
{
Config: providerConfig + `

resource "trocco_team" "test" {
name = "updated"
description = "updated"
members = [
{
user_id = 1
user_id = 10626
role = "team_admin"
},
{
user_id = 2
user_id = 10652
role = "team_member"
}
]
Expand All @@ -62,9 +62,7 @@ func TestAccTeamResource(t *testing.T) {
resource.TestCheckResourceAttr("trocco_team.test", "name", "updated"),
resource.TestCheckResourceAttr("trocco_team.test", "description", "updated"),
resource.TestCheckResourceAttr("trocco_team.test", "members.#", "2"),
resource.TestCheckResourceAttr("trocco_team.test", "members.0.user_id", "1"),
resource.TestCheckResourceAttr("trocco_team.test", "members.0.role", "team_admin"),
resource.TestCheckResourceAttr("trocco_team.test", "members.1.user_id", "2"),
resource.TestCheckResourceAttr("trocco_team.test", "members.1.role", "team_member"),
),
},
Expand Down