Skip to content

Commit

Permalink
ci: add functional tests (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: eeaton <[email protected]>
  • Loading branch information
eeaton and eeaton authored Dec 17, 2024
1 parent 2f8936b commit 1d8a5a1
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 112 deletions.
45 changes: 36 additions & 9 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ steps:
name: "${_BUILDER_IMAGE_NAME}:${_BUILDER_IMAGE_TAG}"
entrypoint: /bin/bash
args:
- "-x"
- "-c"
- >- # folded text - replace newlines with spaces - each command needs to be separated by ';'
cd sample-deployments/composer-orchestrated-process;
export PROJECT_ID=${_TEST_PROJECT_ID};
scripts/pre_tf_setup.sh;
sample-deployments/composer-orchestrated-process/scripts/pre_tf_setup.sh;
env:
- "REGION=${_REGION}"
- "IAP_ADMIN_ACCOUNT=${_IAP_SUPPORT_EMAIL}"
Expand All @@ -48,11 +48,10 @@ steps:
- "-x"
- "-c"
- >-
cd /workspace/build/test ;
export PROJECT_ID=${_TEST_PROJECT_ID};
export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT=${_DEPLOYER_SA};
gcloud config set auth/impersonate_service_account ${_DEPLOYER_SA};
go test -v -run ./ -timeout 90m --tags=e2e
(cd build/test && make e2e-test);
gcloud config unset auth/impersonate_service_account;
entrypoint: /bin/bash
env:
- "REGION=${_REGION}"
Expand All @@ -61,14 +60,41 @@ steps:
- "IAP_ACCESS_DOMAINS=${_IAP_ACCESS_DOMAINS}"
- "WEB_UI_DOMAINS=${_WEB_UI_DOMAINS}"
- "GCLOUD_TF_DOWNLOAD=never"
- "CUSTOM_CLASSIFIER_ID=${_CUSTOM_CLASSIFIER_ID}"
- "GOOGLE_IMPERSONATE_SERVICE_ACCOUNT=${_DEPLOYER_SA}"

- id: functional
name: "${_BUILDER_IMAGE_NAME}:${_BUILDER_IMAGE_TAG}"
args:
- "-e"
- "-x"
- "-c"
- >-
export PROJECT_ID=${_TEST_PROJECT_ID};
gcloud composer environments run dpu-composer --project=${_TEST_PROJECT_ID} --location=us-central1 dags list;
build/test/ingest_test_docs.sh;
sleep 180;
gcloud composer environments run dpu-composer --project=${_TEST_PROJECT_ID} --location=us-central1 dags list;
sample-deployments/composer-orchestrated-process/scripts/trigger_workflow.sh;
sleep 1800;
(cd /workspace/build/test && make functional-test);
# sample-deployments/composer-orchestrated-process/scripts/delete_doc.sh;
# sample-deployments/composer-orchestrated-process/scripts/reset_datastore.sh;
entrypoint: /bin/bash
env:
- "CICD_PROJECT_ID=${PROJECT_ID}"
- "TEST_PROJECT_ID=${_TEST_PROJECT_ID}"
- "LOCATION=${_REGION}"
- "COMPOSER_ENV_NAME=dpu-composer"
- "DAG_ID=run_docs_processing"

- id: cleanup
name: "${_BUILDER_IMAGE_NAME}:${_BUILDER_IMAGE_TAG}"
args:
- "-e"
- "-x"
- "-c"
- >-
gcloud config unset auth/impersonate_service_account;
gcloud projects delete ${_TEST_PROJECT_ID} --quiet
entrypoint: /bin/bash

Expand All @@ -86,12 +112,13 @@ substitutions:
_DOC_AI_LOCATION: "us"
_VERTEX_AI_DATA_STORE_REGION: "us"
_BUILDER_IMAGE_NAME: "us-central1-docker.pkg.dev/${PROJECT_ID}/ci/test-builder"
_BUILDER_IMAGE_TAG: "1.0.0"
_BUILDER_IMAGE_TAG: "1.1.0"
# The following subsitutions must be passed by the Cloud Build trigger:
# _BILLING_ACCOUNT
# _FOLDER_ID
# _IAP_ACCESS_DOMAINS
# _IAP_SUPPORT_EMAIL
# _WEB_UI_DOMAINS
# Note that $PROJECT_ID is always the project running the build, distinct from _TEST_PROJECT_ID where test resources are deployed
# PROJECT_ID cannot be overwritten with env substitution, so it takes an extra command in each step `export PROJECT_ID=${_TEST_PROJECT_ID}
# _CUSTOM_CLASSIFIER_ID
# Note that ${PROJECT_ID} is always the project running the build, distinct from _TEST_PROJECT_ID where test resources are deployed
# ${PROJECT_ID} cannot be overwritten with env substitution, so it requires an extra command in each step `export PROJECT_ID=${_TEST_PROJECT_ID}`
4 changes: 2 additions & 2 deletions build/terratest-builder-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ ARG tf_version=1.8.1-1

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Install terratest
RUN apt-get update && apt-get install -y gnupg=2.2.40-1.1 software-properties-common=0.99.30-4.1~deb12u1 curl=7.88.1-10+deb12u7 --no-install-recommends \
# Install terratest and jq
RUN apt-get update && apt-get install -y gnupg=2.2.40-1.1 software-properties-common=0.99.30-4.1~deb12u1 curl=7.88.1-10+deb12u7 jq=1.6-2.1 --no-install-recommends \
&& wget -nv -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | tee /usr/share/keyrings/hashicorp-archive-keyring.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hashicorp.list \
&& apt-get update \
Expand Down
8 changes: 6 additions & 2 deletions build/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

test-e2e: ## Run the end-to-end test
e2e-test: ## Run the end-to-end test
@echo "Running E2E test..."
@go test -v -run ./ -timeout 30m --tags=e2e
@go test -v -run ./ -timeout 90m --tags=e2e

functional-test: ## upload documents, trigger workflows, and check the results
@echo "running functional test..."
@go test -v -run ./ -timeout 60m --tags=functional

.PHONY: help
.DEFAULT_GOAL := help
Expand Down
8 changes: 8 additions & 0 deletions build/test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type TestConfig struct {
VertexAiDataStoreRegion string `env:"VERTEX_AI_DATA_STORE_REGION,required"`
IapAccessDomains string `env:"IAP_ACCESS_DOMAINS,required"`
WebUiDomains string `env:"WEB_UI_DOMAINS,required"`
CustomClassifierId string `env:"CUSTOM_CLASSIFIER_ID, required"`
}

func TestE2e(t *testing.T) {
Expand Down Expand Up @@ -62,6 +63,7 @@ func TestE2e(t *testing.T) {
"webui_domains": config.WebUiDomains,
"docai_location": config.DocAiLocation,
"vertex_ai_data_store_region": config.VertexAiDataStoreRegion,
"custom_classifier_id": config.CustomClassifierId,
},
NoColor: true,
}
Expand All @@ -74,4 +76,10 @@ func TestE2e(t *testing.T) {
terraformOptions := test_structure.LoadTerraformOptions(t, terraformDir)
terraform.InitAndApply(t, terraformOptions)
})

test_structure.RunTestStage(t, "migrate-tfstate", func() {
terraformOptions := test_structure.LoadTerraformOptions(t, terraformDir)
terraformOptions.MigrateState = true
terraform.InitE(t, terraformOptions)
})
}
63 changes: 63 additions & 0 deletions build/test/functional_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2024 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.

//go:build functional

package main

import (
"context"
"log"
"os/exec"
"regexp"
"testing"

"github.com/sethvargo/go-envconfig"
"github.com/stretchr/testify/assert"
)

type CLIConfig struct {
PROJECT_ID string `env:"PROJECT_ID"`
LOCATION string `env:"LOCATION"`
COMPOSER_ENV_NAME string `env:"COMPOSER_ENV_NAME"`
DAG_ID string `env:"DAG_ID"`
}

func TestDAGState(t *testing.T) {
ctx := context.Background()
var c CLIConfig
if err := envconfig.Process(ctx, &c); err != nil {
log.Fatal(err)
}

cmd := exec.Command(
"gcloud", "composer", "environments", "run", c.COMPOSER_ENV_NAME,
"--location", c.LOCATION,
"dags", "list-runs",
"--", "-d", c.DAG_ID,
)

out, err := cmd.Output()
if err != nil {
t.Fatalf("Failed to execute gcloud command: %v", err)
}

output := string(out)
matched, err := regexp.MatchString(`| success |`, output)
if err != nil {
t.Fatalf("Failed to match regex: %v", err)
}

assert.True(t, matched, "DAG run with state 'success' not found in gcloud output")
}
64 changes: 36 additions & 28 deletions build/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ go 1.21
require (
github.com/gruntwork-io/terratest v0.43.0
github.com/sethvargo/go-envconfig v0.9.0
github.com/stretchr/testify v1.9.0
)

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/auth v0.12.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
cloud.google.com/go/iam v1.2.2 // indirect
cloud.google.com/go/storage v1.43.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
Expand All @@ -21,22 +23,24 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.10.0 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down Expand Up @@ -65,27 +69,31 @@ require (
github.com/pquerna/otp v1.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tmccombs/hcl2json v0.3.3 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/urfave/cli v1.22.2 // indirect
github.com/zclconf/go-cty v1.9.1 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.125.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/api v0.211.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 1d8a5a1

Please sign in to comment.