/fabric8-common

A repository for the common go packages of the Fabric8 services

Primary LanguageGo

Fabric8 Common

1. Overview

A repository containing all common packages used by the fabric8 services. This repository addresses issue #3553

Go code shared between fabric8 services can be added here, and then imported by the services. This will add consistency, reliability, clarity, and (hopefully) reduce bugs and circular repo-to-repo dependencies.

Any code added to this repository should also have test code added, that passes "go test .".

Contents of this repository are anticipated to include:

  • Configuration

  • Event bus

  • Logging

    • Common logging format

    • Single initialization

    • Error handling

    • Common HTTP error response format

    • Metrics

  • Utility

  • Validation routines (application name, etc)

  • HTTP/REST (closing result body, URL utils)

  • Auth

    • Loading/parsing public key

    • Service Account token management

    • JWT token parsing (jwt_token to token_string and token_string to jwt_token)

For Contributing to this project, please refer CONTRIBUTING.md

2. Build Project

To build → make build

This will mainly run go build and report any compilation errors. This will NOT generate any executable as fabric8-common is not a service but collection of go packages which will be imported by other fabric8 services.

3. Run Tests

There are two kind of test, unit test and integration test. Unit test does not required Database while Integration test requies Database.

There are two ways to run tests, without docker and with docker. Without docker are mainly use for development and testing on developer machine while with docker are mainly use by CI/CD jobs.

3.1. Without docker

For Unit test, it can be run directly.

  • Run Unit tests → make test-unit-no-coverage, make test-unit

For Integration test, first need to set Database and then run tests.

  • Set Database → docker-compose up -d db

  • Run Integration tests → make test-integration-no-coverage, make test-integration

To remove Database started with docker-compose up -d db, run docker-compose down

3.2. With docker

One can run tests with docker locally but needs extra setup.

First start docker image for this project.

  • Start Docker image → make docker-start (This will start docker image "fabric8-common-local-build")

For Unit test, it can be run directly.

  • Run Unit tests → make docker-test-unit-no-coverage, make docker-test-unit

For Integration test, first need to set Database and then run tests.

  • Set Database → make integration-test-env-prepare (This will start docker image "make_postgres_integration_test_1")

  • Run Integration tests → make docker-test-integration-no-coverage, make docker-test-integration

To remove Docker image started with make docker-start, run make docker-rm

To remove Database started with make integration-test-env-prepare, run make integration-test-env-tear-down