Skip to content

Commit 00f3098

Browse files
Laren-AWSirenepsmithrlhagermlkdaviesford-at-aws
authored
Go unit and integration tests and Dockerfile (awsdocs#4625)
* Updating C# run instructions for WriteMe. (awsdocs#4620) * Adding CODEOWNERS file (awsdocs#4623) * Adding CODEOWNERS file * Update .github/CODEOWNERS.txt Co-authored-by: Liz Kellebrew-Davies <[email protected]> --------- Co-authored-by: Liz Kellebrew-Davies <[email protected]> * Dotnet top level solution (awsdocs#4614) * Add initial solution file with all projects * Update top level solution. * Fixing up some test issues. * Fixing up failing tests and missing configurations. * Updates to failing autoscale tests * Updating for failing tests and setup. * Updating failing tests * Revert "Updates to failing autoscale tests" This reverts commit 511623c. * Updates to wording. * Wrote run_all_tests.bat batch file to run all tests on Windows. Wrote run_all_tests.sh Bash script, updated Dockerfile, and updated README. * Update gov2/README.md Co-authored-by: ford prior <[email protected]> * Apply suggestions from code review Co-authored-by: Liz Kellebrew-Davies <[email protected]> --------- Co-authored-by: Irene Smith <[email protected]> Co-authored-by: Rachel Hagerman <[email protected]> Co-authored-by: Liz Kellebrew-Davies <[email protected]> Co-authored-by: ford prior <[email protected]>
1 parent aed909f commit 00f3098

File tree

9 files changed

+92
-158
lines changed

9 files changed

+92
-158
lines changed

gov2/Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# GA updates: https://github.com/awsdocs/aws-doc-sdk-examples/issues/4129
44
FROM golang:1.19.2
55
COPY . /gov2
6-
RUN cd gov2/dynamodb && \
7-
go build ./...
6+
# If your corporate network blocks proxy.golang.org, uncomment this line.
7+
RUN go env -w GOPROXY=direct
8+
## Run tests in all gov2 folders.
9+
## Pass 'integration' to run_all_tests.sh to run integration tests.
10+
#RUN cd /gov2 && \
11+
# ./run_all_tests.sh
812
CMD ["bash"]

gov2/README.md

+64-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# AWS SDK for Go (v2) code examples
1+
# SDK for Go V2 code examples
22

33
## Overview
44

5-
The code examples in this topic show you how to use the AWS SDK for Go (v2) with AWS.
5+
The code examples in this topic show you how to use the AWS SDK for Go V2 with AWS.
66

7-
The AWS SDK for Go (v2) provides a Go API for AWS infrastructure services. Using the
7+
The SDK for Go V2 provides a Go API for AWS infrastructure services. Using the
88
SDK, you can build applications on top of Amazon S3, Amazon EC2, Amazon DynamoDB,
99
and more.
1010

@@ -42,7 +42,24 @@ A README in each folder describes how to run the example.
4242
* You must have an AWS account, and have your default credentials and AWS Region
4343
configured as described in the
4444
[AWS Tools and SDKs Shared Configuration and Credentials Reference Guide](https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html).
45-
* Go 1.18 or later
45+
* [Go 1.18 or later](https://go.dev/doc/install)
46+
47+
### Run the code
48+
49+
Each example is a Go module that typically contains two packages that you can run:
50+
`hello` and `cmd`. The `hello` package makes a single call to a service to verify that you
51+
can use the service with the SDK. The `cmd` package runs more complex scenarios
52+
to show you how to accomplish specific tasks.
53+
54+
For example, run the `hello` package from the command line:
55+
56+
```
57+
go run ./hello
58+
```
59+
60+
Some examples require command line arguments. In these cases, you can run the example
61+
with a `-h` flag to get help. Each example has a README.md that describes additional
62+
specifics about how to run the example and any other prerequisites.
4663

4764
## Tests
4865

@@ -80,16 +97,53 @@ go test -tags=integration ./...
8097
```
8198

8299
## Docker image (Beta)
100+
83101
This example code will soon be available in a container image
84-
hosted on [Amazon Elastic Container Registry (ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html). This image will be pre-loaded
85-
with all Golang examples with dependencies pre-resolved, allowing you to explore
86-
these examples in an isolated environment.
102+
hosted on [Amazon Elastic Container Registry (Amazon ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html).
103+
The image will be preloaded with all Go examples, with dependencies pre-resolved.
104+
That way, you can explore the examples in an isolated environment.
87105

88-
⚠️ As of January 2023, the [SDK for Go v2 image](https://gallery.ecr.aws/b4v4v1s0/dotnetv3) is available on ECR Public but is still
89-
undergoing active development. Refer to
90-
[this GitHub issue](https://github.com/awsdocs/aws-doc-sdk-examples/issues/4129)
106+
⚠️ As of January 2023, the [SDK for Go V2 image](https://gallery.ecr.aws/b4v4v1s0/gov2) is available in the Amazon ECR Public Gallery but is still undergoing active development. Refer to [this GitHub issue](https://github.com/awsdocs/aws-doc-sdk-examples/issues/4125)
91107
for more information.
92108

109+
### Build the Docker image
110+
111+
1. Install and run Docker on your machine.
112+
2. Navigate to the same directory as this README.
113+
3. Run `docker build -t <image_name> .` and replace `image_name` with a name for the image.
114+
115+
### Launch the Docker container
116+
117+
Run the Docker container with your image using the following command:
118+
119+
**Windows**
120+
121+
```
122+
docker run -it --volume %USERPROFILE%\.aws:/root/.aws <image_name>
123+
```
124+
125+
**macOS or Linux**
126+
```
127+
docker run -it -v ~/.aws/credentials:/root/.aws/credentials <image_name>
128+
```
129+
130+
The terminal initiates a bash instance at the root of the container.
131+
The Go code examples are in the `gov2` folder and can be run by following
132+
the instructions in the READMEs in the various folders.
133+
134+
### Run tests in the Docker container
135+
136+
To run all unit tests and write the output to a file, run the following command
137+
in the `gov2` directory of the container:
138+
139+
```
140+
./run_all_tests.sh
141+
```
142+
143+
To run integration tests, pass an `integration` argument to the `run_all_tests.sh`
144+
script. Integration tests create and destroy AWS resources and will incur charges on your account.
145+
Proceed with caution.
146+
93147
## Additional resources
94148

95149
* [AWS SDK for Go (v2) Developer Guide](https://aws.github.io/aws-sdk-go-v2/docs/)

gov2/run_all_tests.bat

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Rem Run this batch script with no arguments to run unit tests or with 'integration' to run integration tests.
2+
3+
for /d %%a in (*) do (
4+
cd %%a
5+
call go test -tags=%1 ./...
6+
cd ..
7+
)

gov2/run_all_tests.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
function runCommand() {
4+
dt=$(date +%Y-%m-%d)
5+
if [ $@ ] && [ $@ == 'integration' ]
6+
then
7+
kind='integration'
8+
else
9+
kind='unit'
10+
fi
11+
echo Running $kind tests...
12+
for d in ./*/ ; do /bin/bash -c "(cd '$d' && go test -tags=$@ ./... >> /gov2/test-$kind-run-$dt.out)"; done
13+
}
14+
15+
runCommand $1

gov2/sdk/.nocitest

Whitespace-only changes.

gov2/sdk/README.md

-47
This file was deleted.

gov2/sdk/config.go

-46
This file was deleted.

gov2/sdk/go.mod

-20
This file was deleted.

gov2/sdk/go.sum

-33
This file was deleted.

0 commit comments

Comments
 (0)