Categorygithub.com/TelefonicaTC2Tech/golium
modulepackage
1.2.2
Repository: https://github.com/telefonicatc2tech/golium.git
Documentation: pkg.go.dev

# README

Build codecov Quality Gate Status

Golium

This library aims to speed up the generation of acceptance tests with Cucumber and Behaviour-Driven Development (BDD). It is based on godog which is the official Cucumber BDD framework for Golang.

This library leverages godog with 2 main additions:

  • Introduce a context in the step functions. The context is based on the standard Golang context: context.Context. It enables to share information among steps without using global variables.
  • Provide common steps for some protocols. The current version provides steps for HTTP and DNS protocols.

This is a very initial version which may suffer big changes in the short-term.

Configuration

The library has a default configuration. However, these settings can be changed with environment variables.

Environment VariableDefaultDescription
SUITEgoliumSuite name (for logging purposes)
ENVIRONMENTlocalName of the environment. Golium reads the environment configuration from the file ${DIR_ENVIRONMENTS}/${ENVIRONMENT}.yml. This configuration is mandatory. An optional configuration file to separate sensitive data can be placed at ${DIR_ENVIRONMENTS}/${ENVIRONMENT}-private.yml. Configuration is available to steps with the function GetEnvironment().
DIR_SCHEMAS./schemasDirectory where the JSON schemas are available. These JSON schemas are used by some steps to validate some output (e.g. the body of the HTTP response).
DIR_ENVIRONMENTS./environmentsDirectory where the configuration for each environment is available. Each environment must have a yml file in this directory.
LOG_DIRECTORY./logsDirectory where logs are written. There may be multiple log files. Currently, there is one for tracing the execution of the steps and scenarios (golium.log) and another one to save the HTTP requests and HTTP responses (http.log).
LOG_LEVELINFOLog level. Possible values are defined by logrus library.
LOG_ENCODEfalseEncode sensible values when configured. Each encoder has its pre-defined sensible values

Example

The library includes a complete example with some scenarios for HTTP and DNS protocols in the directory test/acceptance.

Environment

Using docker-compose to build test environment with all dependent services for each example: redis, rabbit, elasticsearch and minio:

docker-compose build

Tests

Run acceptance tests:

docker-compose run --rm golium sh -c "make test-acceptance"

Run tests filtering by tag:

docker-compose run --rm golium sh -c "make test-run-tag TAG=@rabbit"

The examples contains the following directories:

  • features. Features for the test suite in BDD.
  • environments. It contains the configuration for each environment in a specific yml file. This directory is configured with the environment variable: DIR_ENVIRONMENTS.
  • schemas. JSON schemas. This is used by some steps to validate an input (e.g. the HTTP response body). This directory is configured with the environment variable: DIR_SCHEMAS.
  • logs. It stores the log files generated by the execution of the suite tests.

License

Copyright 2021 Telefonica Cybersecurity & Cloud Tech SL

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or lied.
See the License for the specific language governing permissions and
limitations under the License.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
ContainsString check if a expected value is included in a slice of values.
ConvertTableColumnToArray converts a godog table with 1 column into a []string.
ConvertTableToMap converts a godog table with 2 columns into a map[string]interface{}.
ConvertTableToMultiMap converts a godog table with 2 columns into a map[string][]string.
No description provided by the author
No description provided by the author
GetConfig returns the golium configuration.
GetContext returns the Context stored in context.
GetEnvironment returns the environment configuration.
GetLogger returns the logger for DNS requests and responses.
InitializeContext adds the Context to the context.
LoggerFactory returns a Logger instance.
NewBoolConverter Constructor.
NewComplex64Converter Constructor.
NewComposedTag creates a ComposedTag.
NewFloat64Converter Constructor.
NewInt64Converter Constructor.
NewLauncher with a default configuration.
NewLauncherWithYaml with a configuration from a yaml file.
NewMapFromJSONBytes creates a Map from a slice of bytes of a JSON document.
NewNamedTag creates a NamedTag.
NewSliceConverter Constructor.
NewStringConverter Constructor.
NewStringTag creates a Tag that evaluated to the string without any modification.
NewTable Aux function that creates a new table from string matrix for testing purposes.
NewUInt64Converter Constructor.
Remove headers form table.
Value converts a value as a string to consider some golium patterns.
ValueAsInt invokes Value and converts the return value to int.
ValueAsString invokes Value and converts the return value to string.

# Constants

No description provided by the author

# Variables

No description provided by the author

# Structs

ComposedTag is a composition of tags, including StringTags, NamedTags and other ComposedTags to provide an evaluation.
Context contains the context required for common utilities.
FieldConversor.
Launcher is responsible to launch golium (based on godog).
Logger logs in a configurable file.
NamedTag is a Tag that can be evaluated with a tag function depending on the name of the tag.
StringTag represents a implicit tag composed of a text.

# Interfaces

KindFormatter with format to apply conversion.
Map is an interface to get elements from a data structure with a dot notation.
StepsInitializer is an interface to initialize the steps in godog, but extending godog initializer with a context.
Tag interface to calculate the value of a tag.

# Type aliases

ConfigurePattern func to apply transformation into destination.
ContextKey defines a type to store the Context in context.Context.