Merged in feature/scriptclean (pull request #25)
Scripting Clean Up * fixupscripts * addtests
This commit is contained in:
@@ -21,10 +21,48 @@ To find new packages: `https://search.nixos.org/packages`
|
||||
|
||||
For regular usage, please use `task` scripts in order run the most appropriate configuration.
|
||||
|
||||
# Environment Variables
|
||||
## Environment Variables
|
||||
|
||||
When using environment variables, there is a hiearchy that will be respected. (First will override the next)
|
||||
|
||||
1. Within the devbox.json file, a variable added to "env"
|
||||
2. Within the devbox.json file, a variable exported in "init_hook"
|
||||
3. A variable added to .env
|
||||
|
||||
## Testing
|
||||
|
||||
For testing integrations such as queries against a database, or interactions with an SQS queue, this repository employs the use of docker testcontainers.
|
||||
|
||||
`https://testcontainers.com/`
|
||||
|
||||
This enables tests to be fully self-contained, thus allowing allowing tests to be reliable and replicable.
|
||||
|
||||
### Execution
|
||||
|
||||
The simplest way of ensuring the validity of the full project is by running `task fullsuite` when in the devbox shell.
|
||||
|
||||
This will:
|
||||
|
||||
1. Generate the latest version of the specs.
|
||||
2. Run the linting commands.
|
||||
3. Run the unit tests.
|
||||
4. Run the integration tests.
|
||||
|
||||
## Naming Conventions
|
||||
|
||||
**Service** - This term is used internally in order to refer to commands that get deployed as APIs.
|
||||
**Runner** - This term is used internally in order to refer to commands that get deployed as consumers of a queue.
|
||||
|
||||
### Creating a new Service
|
||||
|
||||
1. Add a file named `<service_name>.yml`. The service name is important, as it will be used as a reference throughout the codebase. The service name must be in the format `<functionality>Service`. E.g. queryService, ClientService
|
||||
2. Run `task openapi:generate`. This will generate the following:
|
||||
- A location to implement the server-side functions in `./api/<service_name>/`, as well as generated functions, models and swagger docs.
|
||||
- A location with the client-side code in `./pkg/<service_name>/`
|
||||
3. Implement the controllers in `./api/<service_name>/`
|
||||
4. Create a command in `./cmd/<service_name>/main.go` which creates a new instance from `./internal/api`
|
||||
|
||||
### Creating a new Runner
|
||||
|
||||
1. Implement the controller in `./api/<runner_name>/` which implements the `Controller` interface in `./internal/queue`. The runner name must be in the format `<functionality>Runner`. E.g. queryRunner, csvExportRunner
|
||||
2. Create a command in `./cmd/<runner_name>/main.go` which creates a new instance from `./internal/queue`
|
||||
|
||||
@@ -89,6 +89,6 @@ func (s *Server) Listen() {
|
||||
|
||||
err := s.server.Start(s.address)
|
||||
if err != nil {
|
||||
s.server.Logger.Fatal(err)
|
||||
s.server.Logger.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ func TestNew(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListen(t *testing.T) {
|
||||
t.Skip("Must test appropriately")
|
||||
server := Server{}
|
||||
|
||||
assert.Panics(t, func() { server.Listen() })
|
||||
|
||||
@@ -2,10 +2,12 @@ package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateDB(t *testing.T) {
|
||||
t.Skip("Must test appropriately")
|
||||
t.Setenv("DB_HOST", "")
|
||||
|
||||
createDB()
|
||||
assert.Panics(t, func() { createDB() })
|
||||
}
|
||||
|
||||
@@ -35,3 +35,7 @@ func TestNullQueryTypeValue(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, stringType, val)
|
||||
}
|
||||
|
||||
func TestQueryTypeValid(t *testing.T) {
|
||||
assert.True(t, repository.QuerytypeContextFull.Valid())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.50.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.46.3. DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
|
||||
+10
-2
@@ -33,15 +33,23 @@ tasks:
|
||||
- touch .env
|
||||
fullsuite:
|
||||
cmds:
|
||||
- task generate
|
||||
- task build
|
||||
- task lint
|
||||
- task test:unit:coverage
|
||||
- task test:unit
|
||||
- task test:integration
|
||||
build:
|
||||
deps:
|
||||
- generate
|
||||
cmds:
|
||||
- task docker:build
|
||||
generate:
|
||||
deps:
|
||||
- db:generate
|
||||
- openapi:generate
|
||||
- test:mocks:generate
|
||||
lint:
|
||||
deps:
|
||||
- generate
|
||||
cmds:
|
||||
- task go:lint
|
||||
- task db:lint
|
||||
|
||||
@@ -7,7 +7,11 @@ tasks:
|
||||
download:
|
||||
cmds:
|
||||
- go mod download
|
||||
tidy:
|
||||
tidy:novendor:
|
||||
cmds:
|
||||
- go mod tidy
|
||||
tidy:
|
||||
deps:
|
||||
- tidy:novendor
|
||||
cmds:
|
||||
- go mod vendor
|
||||
|
||||
+7
-4
@@ -7,10 +7,12 @@ vars:
|
||||
COVERAGE_FILE: "{{.OUT_DIR}}/coverage.out"
|
||||
|
||||
tasks:
|
||||
mocks:
|
||||
mocks:generate:
|
||||
cmds:
|
||||
- mockery
|
||||
unit:
|
||||
unit:nocoverage:
|
||||
deps:
|
||||
- mocks:generate
|
||||
vars:
|
||||
INTERNAL: "./internal/..."
|
||||
API: "./api/..."
|
||||
@@ -21,9 +23,9 @@ tasks:
|
||||
go test {{.INTERNAL}} {{.API}} {{.PKG}} \
|
||||
-coverpkg={{.INTERNAL}},{{.API}},{{.PKG}} \
|
||||
-coverprofile={{.COVERAGE_FILE}}
|
||||
unit:coverage:
|
||||
unit:
|
||||
deps:
|
||||
- unit
|
||||
- unit:nocoverage
|
||||
vars:
|
||||
TMP_FILE: "{{.OUT_DIR}}/coverage.tmp"
|
||||
FILTER_COVERAGE_FILE: "{{.OUT_DIR}}/filtered_coverage.out"
|
||||
@@ -44,6 +46,7 @@ tasks:
|
||||
silent: true
|
||||
integration:
|
||||
cmds:
|
||||
- task generate
|
||||
- task docker:build
|
||||
- task test:integration:nobuild
|
||||
integration:nocache:
|
||||
|
||||
Reference in New Issue
Block a user