Skip to content

Commit

Permalink
Base rate sub system unit tests (#356)
Browse files Browse the repository at this point in the history
* Base rate test structure added, Proto updated

* Upload base rate unit test added

* GetBaseRates test fixed

* Updated simType with already exist constant

* Readme updated

* C4 diagrams urls updated in readme

* Coverage flag added on test command

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Code formating

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Utils test cases added

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Failed CSV updated

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Failed CSV updated for unit test

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Util unit test coverage

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Validation test cases added, Server error test cases added

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* GetBaseRate, GetBaseRates repo unit test cases added

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* UploadeBaseRates repo unit test added

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* UploadeBaseRate reop unit test case fix

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Base rate repo utils unit test updated

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

* Base rate seperated out test in sub-tests

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>

Signed-off-by: salman-codewar <salmannaseem131@gmail.com>
Co-authored-by: Brackley cassinga <pcassinga@gmail.com>
  • Loading branch information
salman-codewar and Brackleycassinga committed Nov 30, 2022
1 parent a5be6bf commit bddf427
Show file tree
Hide file tree
Showing 20 changed files with 680 additions and 209 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,3 +19,4 @@
node_modules
.env

systems/data-plan/base-rate/cover.
14 changes: 10 additions & 4 deletions systems/data-plan/README.md
Expand Up @@ -41,7 +41,7 @@ Base rate sub-system is responsibe of:

**UploadBaseRates**

<img src="https://raw.githubusercontent.com/ukama/ukama/upload-rates/systems/data-plan/docs/digrams/UploadBaseRates.png" alt="J" width="500"/>
<img src="https://raw.githubusercontent.com/ukama/ukama/main/systems/data-plan/docs/digrams/UploadBaseRates.png" alt="upload-base-rate" width="500"/>

Upload base rates service provide functionality to populate rates from CV file to DB.

Expand Down Expand Up @@ -69,7 +69,7 @@ Function take these arguments:

**GetBaseRates**

<img src="https://raw.githubusercontent.com/ukama/ukama/upload-rates/systems/data-plan/docs/digrams/GetBaseRates.png" alt="J" width="500"/>
<img src="https://raw.githubusercontent.com/ukama/ukama/main/systems/data-plan/docs/digrams/GetBaseRates.png" alt="get-base-rates" width="500"/>

Get base rates service provide functionality to fetch base rates, and filter data on some required and optional arguments.

Expand Down Expand Up @@ -100,7 +100,7 @@ Function take these arguments:

**GetBaseRate**

<img src="https://raw.githubusercontent.com/ukama/ukama/upload-rates/systems/data-plan/docs/digrams/GetBaseRate.png" alt="J" width="500"/>
<img src="https://raw.githubusercontent.com/ukama/ukama/main/systems/data-plan/docs/digrams/GetBaseRate.png" alt="get-base-rate" width="500"/>

Get base rate service provide functionality to fetch base rate by base rate id.

Expand Down Expand Up @@ -138,7 +138,13 @@ Then navigate into base-rate directory and run below command:
make gen
```

This command will generate protobuf from `pb/rate.proto`.
This command will generate protobuf and mocks from `pb/rate.proto`.

```
make test
```

This command will run the unit tests.

```
make server
Expand Down
12 changes: 10 additions & 2 deletions systems/data-plan/base-rate/Makefile
Expand Up @@ -2,19 +2,27 @@ include ../../config.mk

.PHONY: integration.test test build lint deps

build: integration.build
build:
@echo Building version: \"$(BIN_VER)\"
env CGO_ENABLED=0 go build -ldflags='-X github.com/ukama/ukama/systems/data-plan/base-rate/cmd/version.Version=$(BIN_VER) -extldflags=-static' -o bin/rate cmd/server/main.go
env CGO_ENABLED=0 go build -ldflags='-X github.com/ukama/ukama/systems/data-plan/base-rate/cmd/version.Version=$(BIN_VER) -extldflags=-static' -o bin/base-rate cmd/server/main.go

test:
go test ./... -coverprofile=coverage.out && go tool cover -html=coverage.out


lint:
golangci-lint run

gen:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
pb/rate.proto

mockery --all --recursive --dir ./pkg
mockery --dir ./pb --all --recursive --output ./pb/gen/mocks

clean:
rm pb/gen/*.go

server:
go run cmd/server/main.go
4 changes: 3 additions & 1 deletion systems/data-plan/base-rate/go.mod
Expand Up @@ -3,11 +3,14 @@ module github.com/ukama/ukama/systems/data-plan/base-rate
go 1.18

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/jszwec/csvutil v1.7.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.1
github.com/tj/assert v0.0.3
google.golang.org/grpc v1.50.1
google.golang.org/protobuf v1.28.1
gorm.io/driver/postgres v1.4.5
gorm.io/gorm v1.24.1-0.20221019064659-5dd2bb482755
)

Expand All @@ -31,7 +34,6 @@ require (
github.com/prometheus/procfs v0.7.3 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
gorm.io/driver/postgres v1.4.5 // indirect
)

require (
Expand Down
5 changes: 5 additions & 0 deletions systems/data-plan/base-rate/go.sum
Expand Up @@ -39,6 +39,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down Expand Up @@ -440,6 +442,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ukama/ukama/systems/common v0.0.0-20221101065518-a25964290acc h1:Xlg3Hw9Y8vNQ462Gale+ASGb8rx0t2clncGTnEzV3p4=
github.com/ukama/ukama/systems/common v0.0.0-20221101065518-a25964290acc/go.mod h1:GseFbMTy8dKOm3XWY5BsASTrgu77zL1115Ithu4z43U=
Expand Down Expand Up @@ -831,6 +835,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
2 changes: 1 addition & 1 deletion systems/data-plan/base-rate/mocks/BaseRateRepo.go

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

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

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

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

0 comments on commit bddf427

Please sign in to comment.