Skip to content

Commit 7033a16

Browse files
authored
Add Integration test suite for AD (opendistro-for-elasticsearch#13)
include docker compose, since integration test requires latest odfe cluster running locally. Make file to run some of mostly used go commands. Created integration test for ad plugin. Integration test file is created with tag integration, hence, it will not be executed if user runs unit test. Also, integration tests are long running, docker dependent tests, it is better to run only if preconditions are met.
1 parent 85f8e24 commit 7033a16

File tree

7 files changed

+571
-1
lines changed

7 files changed

+571
-1
lines changed

.github/workflows/odfe-cli-test-build-workflow.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,23 @@ jobs:
4949
version: v1.28
5050
working-directory: odfe-cli
5151

52-
- name: Run Test
52+
- name: Run Unit Tests
5353
env:
5454
GOPROXY: "https://proxy.golang.org"
5555
run: |
5656
go test ./... -coverprofile=coverage.out
5757
go tool cover -func=coverage.out
5858
59+
- name: Run Docker Image
60+
run: |
61+
make docker.start.components
62+
sleep 60
63+
64+
- name: Run Integration Tests
65+
env:
66+
GOPROXY: "https://proxy.golang.org"
67+
run: make test.integration
68+
5969
- name: Upload coverage to Codecov
6070
uses: codecov/codecov-action@v1.0.3
6171
with:

odfe-cli/Makefile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# we will put our integration testing in this path
2+
INTEGRATION_TEST_PATH=./it
3+
4+
# set of env variables that you need for testing
5+
ENV_LOCAL_TEST=\
6+
ODFE_ENDPOINT="https://localhost:9200" \
7+
ODFE_USER="admin" \
8+
ODFE_PASSWORD="admin"
9+
10+
# this command will start a docker components that we set in docker-compose.yml
11+
docker.start.components:
12+
docker-compose up -d;
13+
14+
# shutting down docker components
15+
docker.stop:
16+
docker-compose down;
17+
18+
# clean up docker
19+
docker.clean:
20+
docker system prune --volumes;
21+
22+
# this command will trigger integration test
23+
# INTEGRATION_TEST_SUITE_PATH is used for run specific test in Golang
24+
test.integration:
25+
go clean -testcache;
26+
$(ENV_LOCAL_TEST) go test -tags=integration $(INTEGRATION_TEST_PATH);
27+
28+
test.unit:
29+
go clean -testcache;
30+
go test ./...;
31+
32+
# format project using goimports tool
33+
format:
34+
goimports -w .;
35+
36+
# generate odfe-cli file in current directory
37+
# update GOOS / GOARCH if you want to build for other os and architecture
38+
build:
39+
go build .

odfe-cli/docker-compose.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copied from https://opendistro.github.io/for-elasticsearch-docs/docs/install/docker/
2+
# removed node-2 since we don't need to create two node cluster for integration test
3+
version: '3'
4+
services:
5+
odfe-test-node1:
6+
image: amazon/opendistro-for-elasticsearch:${ODFE_VERSION:-latest}
7+
container_name: odfe-test-node1
8+
environment:
9+
- cluster.name=odfe-test-cluster
10+
- node.name=odfe-test-node1
11+
- discovery.seed_hosts=odfe-test-node1
12+
- cluster.initial_master_nodes=odfe-test-node1
13+
- bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
14+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
15+
ulimits:
16+
memlock:
17+
soft: -1
18+
hard: -1
19+
nofile:
20+
soft: 65536 # maximum number of open files for the Elasticsearch user, set to at least 65536 on modern systems
21+
hard: 65536
22+
volumes:
23+
- odfe-test-data1:/usr/share/elasticsearch/data
24+
ports:
25+
- 9200:9200
26+
- 9600:9600 # required for Performance Analyzer
27+
networks:
28+
- odfe-test-net
29+
30+
volumes:
31+
odfe-test-data1:
32+
33+
networks:
34+
odfe-test-net:

odfe-cli/go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
4949
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
5050
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
5151
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
52+
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
5253
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
5354
github.com/hashicorp/go-retryablehttp v0.6.7 h1:8/CAEZt/+F7kR7GevNHulKkUjLht3CPmn7egmhieNKo=
5455
github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=

0 commit comments

Comments
 (0)