-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a0a4f2
commit b9dc0b6
Showing
6 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
image: gitpod/workspace-go | ||
tasks: | ||
- init: go get | ||
- name: Start acceptance Test Environment | ||
command: make testacc-up | ||
openMode: split-right | ||
# Port 8080 is used for acceptance testing, and we don't need to open it when the container comes up | ||
ports: | ||
- port: 8080 | ||
onOpen: ignore | ||
vscode: | ||
extensions: | ||
- golang.Go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
default: test | ||
|
||
GOBIN = $(shell pwd)/bin | ||
|
||
test: ## Run unit tests. | ||
go test -v ./... | ||
|
||
fmt: tool-golangci-lint ## Format files and fix issues. | ||
gofmt -w -s . | ||
$(GOBIN)/golangci-lint run --fix | ||
|
||
lint-golangci: tool-golangci-lint ## Run golangci-lint linter (same as fmt but without modifying files). | ||
$(GOBIN)/golangci-lint run | ||
|
||
SERVICE ?= gitlab-ce | ||
GITLAB_TOKEN ?= ACCTEST1234567890123 | ||
GITLAB_BASE_URL ?= http://127.0.0.1:8080/api/v4 | ||
|
||
testacc-up: ## Launch a GitLab instance. | ||
docker-compose up -d $(SERVICE) | ||
./scripts/await-healthy.sh | ||
|
||
testacc-down: ## Teardown a GitLab instance. | ||
docker-compose down | ||
|
||
# TOOLS | ||
# Tool dependencies are installed into a project-local /bin folder. | ||
|
||
tool-golangci-lint: | ||
@$(call install-tool, github.com/golangci/golangci-lint/cmd/golangci-lint) | ||
|
||
define install-tool | ||
cd tools && GOBIN=$(GOBIN) go install $(1) | ||
endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
version: '3' | ||
|
||
# Functional tests depend on a running GitLab instance. | ||
# Only one of these services should be run at a time. | ||
services: | ||
gitlab-ce: | ||
image: gitlab/gitlab-ce | ||
restart: always | ||
ports: | ||
- 8080:80 | ||
environment: | ||
GITLAB_ROOT_PASSWORD: adminadmin | ||
labels: | ||
terraform-provider-gitlab/owned: '' | ||
volumes: | ||
- config-ce:/etc/gitlab | ||
- logs-ce:/var/log/gitlab | ||
- data-ce:/var/opt/gitlab | ||
- ${PWD}/scripts/healthcheck-and-setup.sh:/healthcheck-and-setup.sh:Z | ||
healthcheck: | ||
test: /healthcheck-and-setup.sh | ||
interval: 10s | ||
timeout: 2m | ||
|
||
# Valid license file must be provided in order to utilize this service | ||
gitlab-ee: | ||
image: gitlab/gitlab-ee | ||
restart: always | ||
ports: | ||
- 8080:80 | ||
environment: | ||
GITLAB_ROOT_PASSWORD: adminadmin | ||
GITLAB_LICENSE_FILE: /Gitlab-license.txt | ||
labels: | ||
terraform-provider-gitlab/owned: '' | ||
volumes: | ||
- config-ee:/etc/gitlab | ||
- logs-ee:/var/log/gitlab | ||
- data-ee:/var/opt/gitlab | ||
- ${PWD}/scripts/healthcheck-and-setup.sh:/healthcheck-and-setup.sh:Z | ||
- ${PWD}/Gitlab-license.txt:/Gitlab-license.txt:Z | ||
healthcheck: | ||
test: /healthcheck-and-setup.sh | ||
interval: 10s | ||
timeout: 2m | ||
|
||
volumes: | ||
config-ce: | ||
logs-ce: | ||
data-ce: | ||
config-ee: | ||
logs-ee: | ||
data-ee: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env sh | ||
|
||
printf 'Waiting for GitLab container to become healthy' | ||
|
||
until test -n "$(docker ps --quiet --filter label=terraform-provider-gitlab/owned --filter health=healthy)"; do | ||
printf '.' | ||
sleep 5 | ||
done | ||
|
||
echo | ||
echo 'GitLab is healthy' | ||
|
||
# Print the version, since it is useful debugging information. | ||
curl --silent --show-error --header 'Authorization: Bearer ACCTEST1234567890123' http://127.0.0.1:8080/api/v4/version | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env sh | ||
|
||
# This script is intended to be used as a Docker HEALTHCHECK for the GitLab container. | ||
# It prepares GitLab prior to running acceptance tests. | ||
# | ||
# This is a known workaround for docker-compose lacking lifecycle hooks. | ||
# See: https://github.com/docker/compose/issues/1809#issuecomment-657815188 | ||
|
||
set -e | ||
|
||
# Check for a successful HTTP status code from GitLab. | ||
curl --silent --show-error --fail --output /dev/null 127.0.0.1:80 | ||
|
||
# Because this script runs on a regular health check interval, | ||
# this file functions as a marker that tells us if initialization already finished. | ||
done=/var/gitlab-acctest-initialized | ||
|
||
test -f $done || { | ||
echo 'Initializing GitLab for acceptance tests' | ||
|
||
echo 'Creating access token' | ||
( | ||
printf 'terraform_token = PersonalAccessToken.create(' | ||
printf 'user_id: 1, ' | ||
printf 'scopes: [:api, :read_user], ' | ||
printf 'name: :terraform);' | ||
printf "terraform_token.set_token('ACCTEST1234567890123');" | ||
printf 'terraform_token.save!;' | ||
) | gitlab-rails console | ||
|
||
# 2020-09-07: Currently Gitlab (version 13.3.6 ) doesn't allow in admin API | ||
# ability to set a group as instance level templates. | ||
# To test resource_gitlab_project_test template features we add | ||
# group, project myrails and admin settings directly in scripts/start-gitlab.sh | ||
# Once Gitlab add admin template in API we could manage group/project/settings | ||
# directly in tests like TestAccGitlabProject_basic. | ||
# Works on CE too | ||
|
||
echo 'Creating an instance level template group with a simple template based on rails' | ||
( | ||
printf 'group_template = Group.new(' | ||
printf 'name: :terraform, ' | ||
printf 'path: :terraform);' | ||
printf 'group_template.save!;' | ||
printf 'application_settings = ApplicationSetting.find_by "";' | ||
printf 'application_settings.custom_project_templates_group_id = group_template.id;' | ||
printf 'application_settings.save!;' | ||
printf 'attrs = {' | ||
printf 'name: :myrails, ' | ||
printf 'path: :myrails, ' | ||
printf 'namespace_id: group_template.id, ' | ||
printf 'template_name: :rails, ' | ||
printf 'id: 999};' | ||
printf 'project = ::Projects::CreateService.new(User.find_by_username("root"), attrs).execute;' | ||
printf 'project.saved?;' | ||
) | gitlab-rails console | ||
|
||
touch $done | ||
} | ||
|
||
echo 'GitLab is ready for acceptance tests' |