From 190bbbb703b2cafeddabc203e0be52220c5c6564 Mon Sep 17 00:00:00 2001 From: Andrew Dewar Date: Fri, 27 Oct 2023 12:57:28 -0600 Subject: [PATCH] Update mocks/"how to mock" in readme --- README.md | 99 ++++++++++++---------- pkg/cache/cache_mock.go | 2 +- pkg/dao/domain_dao_mock.go | 11 ++- pkg/dao/metrics_mock.go | 11 ++- pkg/dao/repositories_mock.go | 11 ++- pkg/dao/repository_configs_mock.go | 2 +- pkg/dao/rpms_mock.go | 11 ++- pkg/dao/snapshots_mock.go | 2 +- pkg/dao/task_info_mock.go | 11 ++- pkg/pulp_client/pulp_client_mock.go | 2 +- pkg/pulp_client/pulp_global_client_mock.go | 2 +- pkg/tasks/client/client_mock.go | 2 +- pkg/tasks/queue/queue_mock.go | 2 +- 13 files changed, 85 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 82cebcce7..d1dacb98f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Content Sources ## What is it? -Content Sources is an application for storing information about external content (currently YUM repositories) in a central location as well as creating snapshots of those repositories, backed by a Pulp server. +Content Sources is an application for storing information about external content (currently YUM repositories) in a central location as well as creating snapshots of those repositories, backed by a Pulp server. ## Developing @@ -16,27 +16,27 @@ Content Sources is an application for storing information about external content Create a config file from the example: - ```sh - $ cp ./configs/config.yaml.example ./configs/config.yaml - ``` +```sh +$ cp ./configs/config.yaml.example ./configs/config.yaml +``` ### Build needed kafka container - ```sh - $ make compose-build - ``` +```sh +$ make compose-build +``` ### Start dependency containers - ```sh - $ make compose-up - ``` +```sh +$ make compose-up +``` ### Run the server! - ```sh - $ make run - ``` +```sh +$ make run +``` ### @@ -44,39 +44,40 @@ Hit the API: ```sh $ curl -H "$( ./scripts/header.sh 9999 1111 )" http://localhost:8000/api/content-sources/v1.0/repositories/ - ``` +``` ### Stop dependency containers + When its time to shut down the running containers: - ```sh - $ make compose-down - ``` +```sh +$ make compose-down +``` And clean the volume that it uses by (this stops the container before doing it if it were running): - ```sh - $ make compose-clean - ``` - -> There are other make rules that could be helpful, run `make help` to list them. Some are highlighted below +```sh +$ make compose-clean +``` +> There are other make rules that could be helpful, run `make help` to list them. Some are highlighted below ### HOW TO ADD NEW MIGRATION FILES -You can add new migration files, with the prefixed date attached to the file name, by running the following: + +You can add new migration files, with the prefixed date attached to the file name, by running the following: ``` $ go run cmd/dbmigrate/main.go new ``` ### Database Commands + Migrate the Database ```sh $ make db-migrate-up ``` - Seed the database ```sh @@ -85,9 +86,9 @@ $ make db-migrate-seed Get an interactive shell: - ```sh - $ make db-shell - ``` +```sh +$ make db-shell +``` Or open directly a postgres client by running: @@ -125,7 +126,6 @@ Update the `configs/prometheus.yaml` file to set your hostname instead of `local $ cat ./configs/prometheus.example.yaml | sed "s/localhost/$(hostname)/g" > ./configs/prometheus.yaml ``` - To start prometheus run: ```sh @@ -157,8 +157,8 @@ $ make prometheus-ui rbac_timeout: 30 mocks: rbac: - user_read_write: ["jdoe@example.com","jdoe"] - user_read: ["tdoe@example.com","tdoe"] + user_read_write: ["jdoe@example.com", "jdoe"] + user_read: ["tdoe@example.com", "tdoe"] ``` **Running it** @@ -200,13 +200,20 @@ $ curl -H "$( ./scripts/header.sh 9999 1111 )" http://localhost:8000/api/content $ make openapi ``` +### Generating/Update mocks: + +```sh +$ go generate ./... +``` + ### Configuration -The default configuration file in ./configs/config.yaml.example shows all available config options. Any of these can be overridden with an environment variable. For example "database.name" can be passed in via an environment variable named "DATABASE_NAME". +The default configuration file in ./configs/config.yaml.example shows all available config options. Any of these can be overridden with an environment variable. For example "database.name" can be passed in via an environment variable named "DATABASE_NAME". ### Linting To use golangci-lint: + 1. `make install-golangci-lint` 2. `make lint` @@ -214,21 +221,21 @@ To use pre-commit linter: `make install-pre-commit` ### Code Layout -| Path | Description | -|-----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [api](./api/) | Openapi docs and doc generation code | -| [db/migrations](./db/migrations/) | Database Migrations | | -| [pkg/api](./pkg/api) | API Structures that are used for handling data within our API Handlers | -| [pkg/config](./pkg/config) | Config loading and application bootstrapping code | -| [pkg/dao](./pkg/dao) | Database Access Object. Abstraction layer that provides an interface and implements it for our default database provider (postgresql). It is separated out for abstraction and easier testing | -| [pkg/db](./pkg/db) | Database connection and migration related code | -| [pkg/handler](./pkg/handler) | Methods that directly handle API requests | -| [pkg/middleware](./pkg/middleware)| Hold all the middleware components created for the service. | -| [pkg/event](./pkg/event) | Event message logic. Mre info [here](./pkg/event/README.md). | -| [pkg/models](./pkg/models) | Structs that represent database models (Gorm) | -| [pkg/seeds](./pkg/seeds) | Code to help seed the database for both development and testing | +| Path | Description | +| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | +| [api](./api/) | Openapi docs and doc generation code | +| [db/migrations](./db/migrations/) | Database Migrations | | +| [pkg/api](./pkg/api) | API Structures that are used for handling data within our API Handlers | +| [pkg/config](./pkg/config) | Config loading and application bootstrapping code | +| [pkg/dao](./pkg/dao) | Database Access Object. Abstraction layer that provides an interface and implements it for our default database provider (postgresql). It is separated out for abstraction and easier testing | +| [pkg/db](./pkg/db) | Database connection and migration related code | +| [pkg/handler](./pkg/handler) | Methods that directly handle API requests | +| [pkg/middleware](./pkg/middleware) | Hold all the middleware components created for the service. | +| [pkg/event](./pkg/event) | Event message logic. Mre info [here](./pkg/event/README.md). | +| [pkg/models](./pkg/models) | Structs that represent database models (Gorm) | +| [pkg/seeds](./pkg/seeds) | Code to help seed the database for both development and testing | ## More info - * [Architecture](docs/architecture.md) - * [OpenApi Docs](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/content-services/content-sources-backend/main/api/openapi.json) +- [Architecture](docs/architecture.md) +- [OpenApi Docs](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/content-services/content-sources-backend/main/api/openapi.json) diff --git a/pkg/cache/cache_mock.go b/pkg/cache/cache_mock.go index 6d2437342..f5dd3053c 100644 --- a/pkg/cache/cache_mock.go +++ b/pkg/cache/cache_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package cache diff --git a/pkg/dao/domain_dao_mock.go b/pkg/dao/domain_dao_mock.go index 07d556779..25fe99c3e 100644 --- a/pkg/dao/domain_dao_mock.go +++ b/pkg/dao/domain_dao_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dao @@ -57,13 +57,12 @@ func (_m *MockDomainDao) FetchOrCreateDomain(orgId string) (string, error) { return r0, r1 } -type mockConstructorTestingTNewMockDomainDao interface { +// NewMockDomainDao creates a new instance of MockDomainDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockDomainDao(t interface { mock.TestingT Cleanup(func()) -} - -// NewMockDomainDao creates a new instance of MockDomainDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockDomainDao(t mockConstructorTestingTNewMockDomainDao) *MockDomainDao { +}) *MockDomainDao { mock := &MockDomainDao{} mock.Mock.Test(t) diff --git a/pkg/dao/metrics_mock.go b/pkg/dao/metrics_mock.go index 13bd67949..866df9ab7 100644 --- a/pkg/dao/metrics_mock.go +++ b/pkg/dao/metrics_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dao @@ -79,13 +79,12 @@ func (_m *MockMetricsDao) RepositoryConfigsCount() int { return r0 } -type mockConstructorTestingTNewMockMetricsDao interface { +// NewMockMetricsDao creates a new instance of MockMetricsDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMetricsDao(t interface { mock.TestingT Cleanup(func()) -} - -// NewMockMetricsDao creates a new instance of MockMetricsDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockMetricsDao(t mockConstructorTestingTNewMockMetricsDao) *MockMetricsDao { +}) *MockMetricsDao { mock := &MockMetricsDao{} mock.Mock.Test(t) diff --git a/pkg/dao/repositories_mock.go b/pkg/dao/repositories_mock.go index 987a0d570..33dafbf35 100644 --- a/pkg/dao/repositories_mock.go +++ b/pkg/dao/repositories_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dao @@ -145,13 +145,12 @@ func (_m *MockRepositoryDao) Update(repo RepositoryUpdate) error { return r0 } -type mockConstructorTestingTNewMockRepositoryDao interface { +// NewMockRepositoryDao creates a new instance of MockRepositoryDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepositoryDao(t interface { mock.TestingT Cleanup(func()) -} - -// NewMockRepositoryDao creates a new instance of MockRepositoryDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockRepositoryDao(t mockConstructorTestingTNewMockRepositoryDao) *MockRepositoryDao { +}) *MockRepositoryDao { mock := &MockRepositoryDao{} mock.Mock.Test(t) diff --git a/pkg/dao/repository_configs_mock.go b/pkg/dao/repository_configs_mock.go index 62393be53..01d6d7516 100644 --- a/pkg/dao/repository_configs_mock.go +++ b/pkg/dao/repository_configs_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dao diff --git a/pkg/dao/rpms_mock.go b/pkg/dao/rpms_mock.go index 155968833..e64417858 100644 --- a/pkg/dao/rpms_mock.go +++ b/pkg/dao/rpms_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dao @@ -109,13 +109,12 @@ func (_m *MockRpmDao) Search(orgID string, request api.SearchRpmRequest) ([]api. return r0, r1 } -type mockConstructorTestingTNewMockRpmDao interface { +// NewMockRpmDao creates a new instance of MockRpmDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRpmDao(t interface { mock.TestingT Cleanup(func()) -} - -// NewMockRpmDao creates a new instance of MockRpmDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockRpmDao(t mockConstructorTestingTNewMockRpmDao) *MockRpmDao { +}) *MockRpmDao { mock := &MockRpmDao{} mock.Mock.Test(t) diff --git a/pkg/dao/snapshots_mock.go b/pkg/dao/snapshots_mock.go index f1f59c621..c370f1c83 100644 --- a/pkg/dao/snapshots_mock.go +++ b/pkg/dao/snapshots_mock.go @@ -12,7 +12,7 @@ import ( models "github.com/content-services/content-sources-backend/pkg/models" ) -// MockSnapshotDao is an autogenerated mock type for the MockSnapshotDao type +// MockSnapshotDao is an autogenerated mock type for the SnapshotDao type type MockSnapshotDao struct { mock.Mock } diff --git a/pkg/dao/task_info_mock.go b/pkg/dao/task_info_mock.go index fed4d0a88..c75e6ed37 100644 --- a/pkg/dao/task_info_mock.go +++ b/pkg/dao/task_info_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package dao @@ -105,13 +105,12 @@ func (_m *MockTaskInfoDao) List(OrgID string, pageData api.PaginationData, filte return r0, r1, r2 } -type mockConstructorTestingTNewMockTaskInfoDao interface { +// NewMockTaskInfoDao creates a new instance of MockTaskInfoDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockTaskInfoDao(t interface { mock.TestingT Cleanup(func()) -} - -// NewMockTaskInfoDao creates a new instance of MockTaskInfoDao. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockTaskInfoDao(t mockConstructorTestingTNewMockTaskInfoDao) *MockTaskInfoDao { +}) *MockTaskInfoDao { mock := &MockTaskInfoDao{} mock.Mock.Test(t) diff --git a/pkg/pulp_client/pulp_client_mock.go b/pkg/pulp_client/pulp_client_mock.go index c81f27b1a..ab4d8bef0 100644 --- a/pkg/pulp_client/pulp_client_mock.go +++ b/pkg/pulp_client/pulp_client_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package pulp_client diff --git a/pkg/pulp_client/pulp_global_client_mock.go b/pkg/pulp_client/pulp_global_client_mock.go index 7076d3667..3d12412f5 100644 --- a/pkg/pulp_client/pulp_global_client_mock.go +++ b/pkg/pulp_client/pulp_global_client_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package pulp_client diff --git a/pkg/tasks/client/client_mock.go b/pkg/tasks/client/client_mock.go index 24f083d24..48fc493d5 100644 --- a/pkg/tasks/client/client_mock.go +++ b/pkg/tasks/client/client_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package client diff --git a/pkg/tasks/queue/queue_mock.go b/pkg/tasks/queue/queue_mock.go index 522917c77..d8832cc7c 100644 --- a/pkg/tasks/queue/queue_mock.go +++ b/pkg/tasks/queue/queue_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.33.0. DO NOT EDIT. package queue