Skip to content

Commit e082eb6

Browse files
V3.0 (#44)
* Bug fix: RandomTimeStampTzWithDecimals RandomTimeStampTzWithDecimals fails due to a typo with the year variable that is being passed * make the function public make the function isSubStringAvailableOnString from private to public * Avoid using future dates Try to use the date that is from the current time, there is no need to place dates for the future * Protect function from null value * Test suite: Randomizer Build unit test cases for randomizer * update the version of mock-data release * reducing the duplicate code in randomizer test cases * update the function name change * All test suites for helper.go * Test cases for functions inside datatype.go * Rearrangement of functions * Unit test cases for engine.go * Small correction to the database config name * The function should send in error so we can trap and understand the error * update go.sum * single test doesn't work with variable functions, so using named function to overcome the issue * Testcases for sql.go * update the skeleton with additional types or objects * remove the database config * test cases for skeletons.go * implemented logger.go testcases * test cases for constraintBackup.go * Testcases for schema.go * reducing variable count * testcases for database.go * testcases for tables.go * format & correction Formatting via go fmt correction to demo database that breaks the check when run concurrently, it now cleans up all the tables on the database * hidden feature and datatype correction separate out the database cleanup for separate function , that can triggered by a hidden vairable replace postgres has the owner to mockdata and datatype cleanup * testcases for worker.go * cleanup * cleanup of testcases * dont remove postgres role * add testcase for copy data function * testcases for filemanager.go * testcase for constraintRestore.go * testcases correction * Introduction of realstic data Now you can choose realistic data to be loaded to the table * Typo & Corrections * testcase for custom.go * Finishing up the v3.0 - Fixing up broken ci job - cleanup the code - update readme * add postgres service to ci.yml * remove macos-latest macos-latest fails with missing dependency, for now there is no need for macos test, we can add and fix anything later if needed * remove ci.yml from being run on v3.0 branch * testing the codecov ci step * codecov works now , removing the branch v3.0 from the workflow actions * Adding / Updating badges + Adding new badges + Making the existing one dynamic * style to flat * Update README.md * Readme update add more clear descriptions to what the subcommands are for * code formatting Make changes to the code based on suggestion by + golangci-lint + goreportcard * fix the Uri to URI * Update badge label length
1 parent 5d4cbcd commit e082eb6

40 files changed

+4921
-498
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@ on:
44
branches:
55
- main
66
- master
7-
- docker-containerizing # for test, remove after pass
87
jobs:
98
tests:
109
strategy:
1110
matrix:
1211
go-version: [1.16.x]
13-
os: [ubuntu-latest, macos-latest]
14-
runs-on: ${{ matrix.os }}
12+
runs-on: ubuntu-latest
13+
services:
14+
postgres:
15+
image: postgres:12
16+
env:
17+
POSTGRES_PASSWORD: postgres
18+
POSTGRES_USER: postgres
19+
POSTGRES_DB: testmockdb
20+
options: >-
21+
--health-cmd pg_isready
22+
--health-interval 10s
23+
--health-timeout 5s
24+
--health-retries 5
25+
ports:
26+
- 5432:5432
1527
steps:
1628
- name: Install Go
1729
uses: actions/setup-go@v2
@@ -28,12 +40,28 @@ jobs:
2840
key: ${{ runner.os }}-v1-go-${{ hashFiles('**/go.sum') }}
2941
restore-keys: |
3042
${{ runner.os }}-v1-go-
43+
3144
- name: Test
32-
run: go test ./... -race -cover
45+
run: make tests
3346

3447
codecov:
3548
needs: tests
49+
name: Code Coverage
3650
runs-on: ubuntu-latest
51+
services:
52+
postgres:
53+
image: postgres:12
54+
env:
55+
POSTGRES_PASSWORD: postgres
56+
POSTGRES_USER: postgres
57+
POSTGRES_DB: testmockdb
58+
options: >-
59+
--health-cmd pg_isready
60+
--health-interval 10s
61+
--health-timeout 5s
62+
--health-retries 5
63+
ports:
64+
- 5432:5432
3765
steps:
3866
- uses: actions/checkout@v2
3967
with:
@@ -42,7 +70,7 @@ jobs:
4270
with:
4371
go-version: '1.16'
4472
- name: Run coverage
45-
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
73+
run: make codecov_tests
4674
- name: Upload coverage to Codecov
4775
run: bash <(curl -s https://codecov.io/bash)
4876

@@ -57,12 +85,30 @@ jobs:
5785
uses: docker/login-action@v1
5886
with:
5987
registry: ghcr.io
60-
username: ${{ github.repository_owner }}
61-
password: ${{ secrets.CR_PAT }}
88+
username: ${{ github.actor }}
89+
password: ${{ secrets.GITHUB_TOKEN }}
6290
- name: Push to GitHub Packages
6391
uses: docker/build-push-action@v2
6492
with:
6593
push: true
6694
context: .
6795
file: ./build/Dockerfile
68-
tags: ghcr.io/art-frela/mock-data:latest
96+
tags: ghcr.io/pivotal-gss/mock-data:latest
97+
98+
add-contributors:
99+
needs: [tests]
100+
name: Adding Contributors
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v2
104+
- uses: BobAnkh/add-contributors@master
105+
with:
106+
REPO_NAME: 'pivotal-gss/mock-data'
107+
CONTRIBUTOR: '## Contributors'
108+
COLUMN_PER_ROW: '6'
109+
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
IMG_WIDTH: '100'
111+
FONT_SIZE: '14'
112+
PATH: '/README.md'
113+
COMMIT_MESSAGE: 'docs(README): update contributors'
114+
AVATAR_SHAPE: 'round'

.github/workflows/test.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
name: unit tests
1+
name: Tests
22
on:
33
push:
44
branches-ignore:
5+
- main
6+
- image
7+
- master
8+
pull_request:
9+
branches:
510
- main
611
- master
712
jobs:
813
tests:
14+
name: tests
915
strategy:
1016
matrix:
1117
go-version: [1.15.x, 1.16.x]
12-
os: [ubuntu-latest, macos-latest]
13-
runs-on: ${{ matrix.os }}
18+
runs-on: ubuntu-latest
19+
services:
20+
postgres:
21+
image: postgres:12
22+
env:
23+
POSTGRES_PASSWORD: postgres
24+
POSTGRES_USER: postgres
25+
POSTGRES_DB: testmockdb
26+
options: >-
27+
--health-cmd pg_isready
28+
--health-interval 10s
29+
--health-timeout 5s
30+
--health-retries 5
31+
ports:
32+
- 5432:5432
1433
steps:
1534
- name: Install Go
1635
uses: actions/setup-go@v2
@@ -27,5 +46,6 @@ jobs:
2746
key: ${{ runner.os }}-v1-go-${{ hashFiles('**/go.sum') }}
2847
restore-keys: |
2948
${{ runner.os }}-v1-go-
49+
3050
- name: Test
31-
run: go test ./... -race -cover
51+
run: make tests

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ linters:
5454
- 'gofmt'
5555
- 'goheader'
5656
- 'goimports'
57-
- 'golint'
57+
- 'revive'
5858
- 'gomodguard'
5959
- 'goprintffuncname'
6060
- 'gosec'
@@ -67,7 +67,7 @@ linters:
6767
- 'paralleltest'
6868
- 'prealloc'
6969
- 'predeclared'
70-
- 'scopelint'
70+
- 'exportloopref'
7171
- 'sqlclosecheck'
7272
- 'staticcheck'
7373
- 'structcheck'

Makefile

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,104 @@
11
IMAGE = "mock:latest"
2+
PGDATABASE = "testmockdb"
3+
PGUSER = "postgres"
4+
PGHOST = "localhost"
5+
PGPORT = 5432
6+
PGPASSWORD = "postgres"
7+
MOCK_DATA_TEST_RUNNER = "true"
28

39
# h - help
410
h help:
5-
@echo "h help - this help"
6-
@echo "docker - run docker image build"
11+
@echo "h, help - Help menu"
12+
@echo "docker - Run docker image build"
13+
@echo "tests - Run all the test suites (Unit & Integration)"
14+
@echo "unit_tests - Run mock data unit test suites"
15+
@echo "integration_tests - Run mock data integration test suites"
16+
@echo "build - Build mock data binary"
17+
@echo "install_postgres - Install postgres locally via brew"
18+
@echo "start_postgres - Start postgres locally via brew"
19+
@echo "stop_postgres - Stop postgres locally via brew"
20+
@echo "uninstall_postgres - Uninstall postgres locally via brew"
21+
@echo "create_db - create a mock database for testing"
22+
@echo "recreate_db - drop if exists and create a mock database for testing"
23+
@echo "drop_db - drop the mock database"
724
.PHONY: h
825

9-
1026
# docker build
1127
docker:
1228
docker build -f ./build/Dockerfile -t $(IMAGE) .
1329
.PHONY: docker
30+
31+
# Run Mock data test Suite
32+
unit_tests:
33+
make recreate_db
34+
@echo "#### Running Mock Data Test"
35+
MOCK_DATA_TEST_RUNNER=$(MOCK_DATA_TEST_RUNNER) PGPASSWORD=$(PGPASSWORD) PGDATABASE=$(PGDATABASE) PGUSER=$(PGUSER) PGHOST=$(PGHOST) PGPORT=$(PGPORT) GOFLAGS="-count=1" go test -v . -race -cover
36+
@echo "#### Finished Mock Data Test"
37+
make drop_db
38+
.PHONY: unit_tests
39+
40+
# Run Mock data loading test for all supported datatype
41+
integration_tests:
42+
make recreate_db
43+
MOCK_DATA_TEST_RUNNER=$(MOCK_DATA_TEST_RUNNER) PGPASSWORD=$(PGPASSWORD) PGDATABASE=$(PGDATABASE) PGUSER=$(PGUSER) PGHOST=$(PGHOST) PGPORT=$(PGPORT) /bin/bash integration_test.sh
44+
make drop_db
45+
.PHONY: integration_tests
46+
47+
# Run Mock data test codecov
48+
codecov_tests:
49+
make recreate_db
50+
@echo "#### Running Mock Data Test"
51+
MOCK_DATA_TEST_RUNNER=$(MOCK_DATA_TEST_RUNNER) PGPASSWORD=$(PGPASSWORD) PGDATABASE=$(PGDATABASE) PGUSER=$(PGUSER) PGHOST=$(PGHOST) PGPORT=$(PGPORT) GOFLAGS="-count=1" go test -v . -coverprofile=coverage.txt -covermode=atomic
52+
@echo "#### Finished Mock Data Test"
53+
make drop_db
54+
.PHONY: unit_tests
55+
56+
# Run all mock data test
57+
tests:
58+
make unit_tests
59+
make integration_tests
60+
.PHONY: tests
61+
62+
# Run Mock data build
63+
build:
64+
/bin/sh build.sh
65+
.PHONY: build
66+
67+
# Run brew install postgres script
68+
install_postgres:
69+
brew install postgresql@12
70+
.PHONY: install_postgres
71+
72+
# Run brew start postgres service
73+
start_postgres:
74+
brew services start postgresql@12
75+
.PHONY: start_postgres
76+
77+
# Run brew stop postgres service
78+
stop_postgres:
79+
brew services stop postgresql@12
80+
.PHONY: stop_postgres
81+
82+
# Run brew uninstall postgres script
83+
uninstall_postgres:
84+
brew uninstall postgresql@12
85+
.PHONY: uninstall_postgres
86+
87+
# Create Mock Database
88+
create_db:
89+
@echo "#### Creating database"
90+
PGPASSWORD=$(PGPASSWORD) PGUSER=$(PGUSER) PGHOST=$(PGHOST) PGPORT=$(PGPORT) psql -Atc "CREATE DATABASE $(PGDATABASE);" template1
91+
.PHONY: create_db
92+
93+
# Recreate Mock Database
94+
recreate_db:
95+
@echo "#### Recreating database"
96+
make drop_db
97+
make create_db
98+
.PHONY: recreate_db
99+
100+
# Drop Mock Database
101+
drop_db:
102+
@echo "#### Dropping database if exists"
103+
PGPASSWORD=$(PGPASSWORD) PGUSER=$(PGUSER) PGHOST=$(PGHOST) PGPORT=$(PGPORT) psql -Atc "DROP DATABASE IF EXISTS $(PGDATABASE);" template1
104+
.PHONY: drop_db

0 commit comments

Comments
 (0)