Repository navigation
94 lines (90 loc) · 3.97 KB
/
Copy pathtest.yml
File metadata and controls
94 lines (90 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: test
on:
push:
branches: [main]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false
- run: go test ./...
# aws-emulator runs the tests that need AWS against AWS Emulator.
# It runs every test, in every package, whose name starts with TestRealAWS.
# Such a test must skip itself if AWSCACHE_TEST_TABLE or
# AWSCACHE_TEST_BUCKET isn't set, so that the test job above skips it.
aws-emulator:
runs-on: ubuntu-latest
env:
# To upgrade, get a version from
# https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/versions.json
# and set the SHA-256 of its amd64 .deb package.
AWS_EMULATOR_VERSION: 1.0.511
AWS_EMULATOR_SHA256: e8365d2b3d83bfe477a6b78e72de29c67e006d0e80964771c9f6467eba8655a1
AWS_EMULATOR_PORT: "9297"
AWSCACHE_TEST_TABLE: awscache-test
AWSCACHE_TEST_BUCKET: awscache-test
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false
- name: Install AWS Emulator
run: |
curl -fsSLo "$RUNNER_TEMP/aws-emulator.deb" \
"https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/aws-emulator_${AWS_EMULATOR_VERSION}-1_amd64.deb"
echo "${AWS_EMULATOR_SHA256} $RUNNER_TEMP/aws-emulator.deb" | sha256sum -c -
sudo apt-get install -y "$RUNNER_TEMP/aws-emulator.deb"
aws-emulator -v
- name: Start AWS Emulator
run: |
nohup aws-emulator --telemetry off -p "$AWS_EMULATOR_PORT" > "$RUNNER_TEMP/aws-emulator.log" 2>&1 &
dir="$HOME/.aws/emulator/$AWS_EMULATOR_PORT"
for i in $(seq 30); do
if curl -sf --cacert "$dir/ca.pem" "https://127.0.0.1:$AWS_EMULATOR_PORT/__admin/health"; then
break
fi
sleep 1
done
curl -sSf --cacert "$dir/ca.pem" "https://127.0.0.1:$AWS_EMULATOR_PORT/__admin/health"
# Point the AWS CLI and the AWS SDK for Go at the emulator for
# all the steps that follow.
{
echo "AWS_ENDPOINT_URL=https://127.0.0.1:$AWS_EMULATOR_PORT"
echo "AWS_SHARED_CREDENTIALS_FILE=$dir/emulator_credentials"
echo "AWS_CONFIG_FILE=$dir/config"
echo "AWS_CA_BUNDLE=$dir/ca.pem"
echo "AWS_EC2_METADATA_DISABLED=true"
echo "AWS_DISABLE_HOST_PREFIX_INJECTION=true"
echo "AWS_REGION=us-east-1"
echo "AWS_DEFAULT_REGION=us-east-1"
} >> "$GITHUB_ENV"
- name: Create AWS resources
run: |
# Make sure that the requests go to the emulator, not to AWS.
test "$(aws sts get-caller-identity --query Account --output text)" = 000000000000
aws dynamodb create-table --table-name "$AWSCACHE_TEST_TABLE" \
--attribute-definitions AttributeName=k,AttributeType=S \
--key-schema AttributeName=k,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
aws dynamodb wait table-exists --table-name "$AWSCACHE_TEST_TABLE"
aws dynamodb update-time-to-live --table-name "$AWSCACHE_TEST_TABLE" \
--time-to-live-specification Enabled=true,AttributeName=ttl
aws s3api create-bucket --bucket "$AWSCACHE_TEST_BUCKET"
- name: Test
run: go test -run '^TestRealAWS' -count=1 -v ./...
- name: Show AWS Emulator log
if: always()
run: cat "$RUNNER_TEMP/aws-emulator.log" || true