storage

package module
v0.0.0-...-e766170 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 4 Imported by: 4

README

Storage

Coverage Status

APIs de armazenamento do dadosjusbr

Como contribuir com os testes e executa-los.

Mocks

Os mocks são importantes peças para conseguirmos simular comportamentos de objetos. Nesse repositório, os mocks são utilizados no arquivo de teste "client_test.go", onde simulamos o comportamento dos diversos métodos que temos nas interfaces dos subdiretórios do diretório "repo".

Sempre que as interfaces forem modificadas, é necessário gerar os mocks novamente, sobrescrevendo os arquivos antigos pelos novos. Eles são gerados automaticamente, utilizando o passo a passo descrito logo a seguir.

Gerando mocks

Estamos utilizando a biblioteca gomock para gerar nossos mocks. Siga a documentação do gomock para conseguir instalar o mockgen no seu computador.

Com o mockgen instalado, basta executar os seguintes comandos:

  • Para gerar os mocks a partir da interface do database:
mockgen --source ./repo/database/interface.go --destination ./repo/database/database_mock.go
  • Para gerar os mocks a partir da interface do file storage:
mockgen --source ./repo/file_storage/interface.go --destination ./repo/file_storage/file_storage_mock.go

Com esses comandos, os mocks antigos são sobrescritos por novos e atualizados.

Subir o banco de teste com o Docker

Para conseguir testar as funcionalidades que acessam diretamente o banco de dados, em /repo/database/postgres_test.go, é necessário ter o banco de dados rodando. Execute os seguintes comandos:

Para buildar a imagem do banco de teste:

docker build -t dadosjusbr_test repo/database

Para subir o banco de dados:

docker run -d --name dadosjusbr_test -p 5432:5432 dadosjusbr_test

Em caso de erro, você pode verificar os logs com o seguinte comando:

docker logs dadosjusbr_test

Para parar o container com o banco de dados, utilize o seguinte comando:

docker stop dadosjusbr_test

Para remover o container, utilize o seguinte comando:

docker rm dadosjusbr_test
Iniciando banco de dados local a partir de seu container
  • Após levantar o banco de dados uma única vez, você poderá dar start nele, todas as vezes que ligar o computador, executando o seguinte comando:
docker start dadosjusbr_test

Rodando os testes

Com todas as configurações feitas, basta executar os seguintes comandos para executar os testes:

  • Para executar todos:
$ go test -v ./...
  • Para executar um:
$ go test -v ${caminho para o arquivo de teste}

Executando o comando, você poderá ver as estatisticas relacionadas aos testes, como tempo que demorou a ser concluido, status, diretório, etc...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Db    database.Interface
	Cloud file_storage.Interface
}

Client is composed by mongoDbClient and Cloud5 client (used for backup).

func NewClient

func NewClient(db database.Interface, cloud file_storage.Interface) (*Client, error)

NewClient NewClient

func (*Client) Close

func (c *Client) Close() error

Close Connection with DB

func (*Client) GetAgenciesCount

func (c *Client) GetAgenciesCount() (int, error)

GetAgenciesCount Return the Agencies amount

func (*Client) GetAllAgencyCollection

func (c *Client) GetAllAgencyCollection(agency string) ([]models.AgencyMonthlyInfo, error)

Get all agency collection

func (*Client) GetAnnualSummary

func (c *Client) GetAnnualSummary(agency string) ([]models.AnnualSummary, error)

func (*Client) GetFirstDateWithMonthlyInfo

func (c *Client) GetFirstDateWithMonthlyInfo() (int, int, error)

GetFirstDateWithMonthlyInfo return the initial year and month with collected data

func (*Client) GetIndexInformation

func (c *Client) GetIndexInformation(name string, month, year int) (map[string][]models.IndexInformation, error)

Get index information by agency's ID or group (name)

func (*Client) GetLastDateWithMonthlyInfo

func (c *Client) GetLastDateWithMonthlyInfo() (int, int, error)

GetLastDateWithMonthlyInfo return the latest year and month with collected data

func (*Client) GetNumberOfMonthsCollected

func (c *Client) GetNumberOfMonthsCollected() (int, error)

GetNumberOfMonthsCollected Return the Agencies amount

func (*Client) GetOMA

func (c *Client) GetOMA(month int, year int, agency string) (*models.AgencyMonthlyInfo, *models.Agency, error)

GetOMA Connect to db to collect data for a month including all employees

func (*Client) GetOPJ

func (c *Client) GetOPJ(group string) ([]models.Agency, error)

GetOPJ Connect to db to collect data to build 'Órgao por jurisdição' screen

func (*Client) GetStateAgencies

func (c *Client) GetStateAgencies(uf string) ([]models.Agency, error)

GetStateAgencies Connect to db to collect state agencies by UF

func (*Client) Store

func (c *Client) Store(agmi models.AgencyMonthlyInfo) error

Store stores the Agency Monthly Info stats.

func (*Client) StorePaychecks

func (c *Client) StorePaychecks(p []models.Paycheck, r []models.PaycheckItem) error

func (*Client) StoreRemunerations

func (c *Client) StoreRemunerations(remu models.Remunerations) error

Directories

Path Synopsis
About used pointers.
About used pointers.
repo
database
Package mock_database is a generated GoMock package.
Package mock_database is a generated GoMock package.
file_storage
Package mock_file_storage is a generated GoMock package.
Package mock_file_storage is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL