Skip to content

Commit e3e1822

Browse files
committed
ci: rework integration tests
- remove unused scripts - run ginkgo suite directly instead of compiling a `.test` binary - test helpers run mysql / postgresql db setup commands directly - remove db setup shell script - tests derive config file name based on DB value, simplifies scripts
1 parent 63601b7 commit e3e1822

17 files changed

Lines changed: 222 additions & 95 deletions

ci/tasks/test-integration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ case "$DB" in
3535
echo "Memory DB Noop"
3636
;;
3737
*)
38-
echo "Usage: DB={mysql|postgresql|memory} $0 {commands}"
38+
echo "Usage: DB={mysql|postgresql|memory} $0"
3939
exit 1
4040
esac
4141

src/config-server/bin/lint

100644100755
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#!/usr/bin/env bash
22
set -eu -o pipefail
33

4-
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
4+
config_server_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
55

66
(
7-
cd "$ROOT_DIR"
7+
cd "${config_server_dir}"
88
if ! command -v golangci-lint &> /dev/null; then
99
go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
1010
fi
1111
)
12-
go_bin_path="$(go env GOPATH)/bin" # TODO this should be handled in the docker container
13-
export PATH=${go_bin_path}:${PATH}
1412

1513
golangci-lint version
1614

1715
linted_os_list=(linux)
1816

19-
for os in ${linted_os_list[*]}; do
17+
for os in "${linted_os_list[@]}"; do
2018
echo -e "\n lint-ing with GOOS=${os}..."
21-
GOOS="${os}" golangci-lint run "${ROOT_DIR}"/...
19+
(
20+
cd "${config_server_dir}"
21+
GOOS="${os}" golangci-lint run ./...
22+
)
2223
done

src/config-server/bin/start_server.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/config-server/bin/test-integration

100644100755
Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,26 @@
11
#!/usr/bin/env bash
22
set -eu -o pipefail
33

4-
export PATH=/usr/local/go/bin:${PATH}
5-
6-
bin=$(dirname $0)
7-
testdir="./tmp"
8-
9-
setup_test_dir (){
10-
rm -rf ${testdir}
11-
mkdir ${testdir}
12-
13-
cp -p "${bin}/start_server.sh" ${testdir}
14-
cp -p "${bin}/stop_server.sh" ${testdir}
15-
cp -p "${bin}/setup_db.sh" ${testdir}
16-
cp -r ./integration/assets ${testdir}/assets
17-
18-
echo 'Building config-server'
19-
go build .
20-
cp -p config-server ${testdir}/config-server
21-
22-
go run github.com/onsi/ginkgo/v2/ginkgo build -r --race integration
23-
24-
mv ./integration/integration.test ${testdir}
25-
pushd ${testdir}
26-
}
27-
28-
setup_test_dir
29-
4+
config_server_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
305

316
run_tests (){
327
export DB=$1
338
echo -e "\n\nRunning Integration tests for $DB\n\n"
349

35-
export CONFIG_FILE="./assets/config.${DB}.json"
36-
./integration.test
10+
pushd "${config_server_dir}"
11+
go run github.com/onsi/ginkgo/v2/ginkgo run -r --race integration
12+
popd
3713
}
3814

39-
case $1 in
40-
memory )
41-
run_tests memory ;;
42-
mysql )
43-
run_tests mysql ;;
44-
postgresql )
45-
run_tests postgresql ;;
46-
* )
47-
if [ -n "$1" ]; then
48-
echo "usage test-integration.sh [memory|postgresql|mysql] Defaults to all"
49-
exit 1
50-
fi
51-
run_tests memory
52-
run_tests mysql
53-
run_tests postgresql
54-
;;
15+
case "${1:-}" in
16+
memory )
17+
run_tests memory ;;
18+
mysql )
19+
run_tests mysql ;;
20+
postgresql )
21+
run_tests postgresql ;;
22+
* )
23+
echo "Usage: ${0} {mysql|postgresql|memory}"
24+
exit 1
25+
;;
5526
esac
56-
57-
popd

src/config-server/integration/id_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ var _ = Describe("Supported HTTP Methods", func() {
1414
var session *gexec.Session
1515

1616
BeforeEach(func() {
17-
SetupDB()
17+
SetupDB(GinkgoWriter)
1818

1919
var err error
20-
cmd := exec.Command(pathToConfigServer, pathToConfigFile)
20+
cmd := exec.Command(pathToConfigServer, ConfigForDb())
2121
session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
2222
Expect(err).NotTo(HaveOccurred())
2323

@@ -35,7 +35,7 @@ var _ = Describe("Supported HTTP Methods", func() {
3535
resultMap := UnmarshalJSONString(response.Body)
3636

3737
Expect(resultMap["id"]).ToNot(BeNil())
38-
Expect(len((resultMap["id"].(string))) > 0).To(BeTrue())
38+
Expect(len(resultMap["id"].(string)) > 0).To(BeTrue())
3939
Expect(resultMap["name"]).To(Equal("Dale"))
4040
Expect(resultMap["value"]).To(Equal("Wick"))
4141
})
@@ -44,12 +44,12 @@ var _ = Describe("Supported HTTP Methods", func() {
4444
response1, _ := SendPutRequest("Dale", "Wick") //nolint:errcheck
4545
resultMap1 := UnmarshalJSONString(response1.Body)
4646
Expect(resultMap1["id"]).ToNot(BeNil())
47-
Expect(len((resultMap1["id"].(string))) > 0).To(BeTrue())
47+
Expect(len(resultMap1["id"].(string)) > 0).To(BeTrue())
4848

4949
response2, _ := SendPutRequest("Alan", "Donovan") //nolint:errcheck
5050
resultMap2 := UnmarshalJSONString(response2.Body)
5151
Expect(resultMap2["id"]).ToNot(BeNil())
52-
Expect(len((resultMap2["id"].(string))) > 0).To(BeTrue())
52+
Expect(len(resultMap2["id"].(string)) > 0).To(BeTrue())
5353

5454
Expect(resultMap1["id"]).ToNot(Equal(resultMap2["id"]))
5555
})

src/config-server/integration/integration_tests_suite_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package integration_test
22

33
import (
4-
"os"
5-
64
. "github.com/onsi/ginkgo/v2"
75
. "github.com/onsi/gomega"
86
"github.com/onsi/gomega/gexec"
@@ -12,7 +10,6 @@ import (
1210

1311
var (
1412
pathToConfigServer string
15-
pathToConfigFile string
1613
)
1714

1815
func TestIntegrationTests(t *testing.T) {
@@ -26,5 +23,4 @@ var _ = SynchronizedBeforeSuite(func() []byte {
2623
return []byte(configServerPath)
2724
}, func(data []byte) {
2825
pathToConfigServer = string(data)
29-
pathToConfigFile = os.Getenv("CONFIG_FILE")
3026
})

src/config-server/integration/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ var _ = Describe("Supported HTTP Methods", func() {
1818
var session *gexec.Session
1919

2020
BeforeEach(func() {
21-
SetupDB()
21+
SetupDB(GinkgoWriter)
2222

2323
var err error
24-
cmd := exec.Command(pathToConfigServer, pathToConfigFile)
24+
cmd := exec.Command(pathToConfigServer, ConfigForDb())
2525
session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
2626
Expect(err).NotTo(HaveOccurred())
2727

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"port": 9000,
3+
"store": "memory",
4+
"certificate_file_path": "support/assets/ssl.crt",
5+
"private_key_file_path": "support/assets/ssl.key",
6+
"jwt_verification_key_path": "support/assets/uaa.pub"
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"port": 9000,
3+
"store": "database",
4+
"database": {
5+
"adapter": "mysql",
6+
"user": "root",
7+
"password": "password",
8+
"host": "127.0.0.1",
9+
"port": 3306,
10+
"db_name": "config_server",
11+
"connection_options": {
12+
"max_open_connections": 32,
13+
"max_idle_connections": 10
14+
}
15+
},
16+
"certificate_file_path": "support/assets/ssl.crt",
17+
"private_key_file_path": "support/assets/ssl.key",
18+
"jwt_verification_key_path": "support/assets/uaa.pub"
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"port": 9000,
3+
"store": "database",
4+
"database": {
5+
"adapter": "postgres",
6+
"user": "postgres",
7+
"password": "password",
8+
"host": "127.0.0.1",
9+
"port": 5432,
10+
"db_name": "config_server",
11+
"connection_options": {
12+
"max_open_connections": 32,
13+
"max_idle_connections": 10
14+
}
15+
},
16+
"certificate_file_path": "support/assets/ssl.crt",
17+
"private_key_file_path": "support/assets/ssl.key",
18+
"jwt_verification_key_path": "support/assets/uaa.pub"
19+
}

0 commit comments

Comments
 (0)