Skip to content

Commit

Permalink
Merge pull request #20 from decentralized-cloud/improving-mock-genera…
Browse files Browse the repository at this point in the history
…tion

Added script for mocks generation
  • Loading branch information
mortezaalizadeh committed Apr 2, 2021
2 parents 0bb3426 + 5e0fd08 commit 35df68c
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 145 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export GOARCH ?= amd64
GOFILES = $(shell find . -type f -name '*.go' -not -path "*/mock/*.go" -not -path "*.pb.go")

.PHONY: all
all: build-grpc dep build install ## Build gRPC contract, get deps, and build, and install binary
all: build-grpc dep build-mocks build install ## Build gRPC contract, get deps, and build, and install binary

.PHONY: clean
clean: ## Clean the working area and the user
Expand All @@ -40,6 +40,10 @@ dep: ## Install dependencies
build-grpc: ## Build grpc
@$(CURRENT_DIRECTORY)/scripts/compile-grpc.sh

.PHONY: build-mocks
build-mocks: ## Build mocks
@$(CURRENT_DIRECTORY)/scripts/build-mocks.sh

.PHONY: build
build: GOARGS += -tags "$(GOTAGS)" -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)
build: ## Build the binary
Expand Down
10 changes: 10 additions & 0 deletions docker/Dockerfile.buildMocks
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM microbusiness/go-toolset:latest
LABEL maintainer="morteza.alizadeh@gmail.com"

ADD . /src
WORKDIR /src
RUN mockgen -source=services/repository/contract.go -destination=services/repository/mock/mock-contract.go
RUN mockgen -source=services/transport/contract.go -destination=services/transport/mock/mock-contract.go
RUN mockgen -source=services/business/contract.go -destination=services/business/mock/mock-contract.go
RUN mockgen -source=services/configuration/contract.go -destination=services/configuration/mock/mock-contract.go
RUN mockgen -source=services/endpoint/contract.go -destination=services/endpoint/mock/mock-contract.go
26 changes: 26 additions & 0 deletions scripts/build-mocks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env sh

set -e
set -x

cleanup() {
docker rm extract-mock-builder
}

trap 'cleanup' EXIT

if [ $# -eq 0 ]; then
current_directory=$(dirname "$0")
else
current_directory="$1"
fi

cd "$current_directory"/..

docker build -f docker/Dockerfile.buildMocks -t mock-builder .
docker create --name extract-mock-builder mock-builder
docker cp extract-mock-builder:/src/services/repository/mock/mock-contract.go ./services/repository/mock/mock-contract.go
docker cp extract-mock-builder:/src/services/transport/mock/mock-contract.go ./services/transport/mock/mock-contract.go
docker cp extract-mock-builder:/src/services/business/mock/mock-contract.go ./services/business/mock/mock-contract.go
docker cp extract-mock-builder:/src/services/configuration/mock/mock-contract.go ./services/configuration/mock/mock-contract.go
docker cp extract-mock-builder:/src/services/endpoint/mock/mock-contract.go ./services/endpoint/mock/mock-contract.go
55 changes: 28 additions & 27 deletions services/business/mock/mock-contract.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 55 additions & 54 deletions services/configuration/mock/mock-contract.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35df68c

Please sign in to comment.