Documentation
¶
Index ¶
- func ContainsString(expected string, values []string) bool
- func ConvertTableColumnToArray(ctx context.Context, t *godog.Table) ([]string, error)
- func ConvertTableToMap(ctx context.Context, t *godog.Table) (map[string]interface{}, error)
- func ConvertTableToMultiMap(ctx context.Context, t *godog.Table) (map[string][]string, error)
- func ConvertTableWithHeaderToStructSlice(ctx context.Context, t *godog.Table, slicePtr interface{}) error
- func ConvertTableWithoutHeaderToStruct(ctx context.Context, t *godog.Table, v interface{}) error
- func GetConfig() *cfg.Config
- func InitializeContext(ctx context.Context) context.Context
- func Value(ctx context.Context, s string) interface{}
- func ValueAsInt(ctx context.Context, s string) (int, error)
- func ValueAsString(ctx context.Context, s string) string
- type ComposedTag
- type Context
- type ContextKey
- type Launcher
- type Map
- type NamedTag
- type StepsInitializer
- type StringTag
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsString ¶
ContainsString check if a expected value is included in a slice of values.
func ConvertTableColumnToArray ¶
ConvertTableColumnToArray converts a godog table with 1 column into a []string.
func ConvertTableToMap ¶
ConvertTableToMap converts a godog table with 2 columns into a map[string]interface{}.
func ConvertTableToMultiMap ¶
ConvertTableToMultiMap converts a godog table with 2 columns into a map[string][]string. The multimap is using url.Values. The multimap is useful to support multiple values for the same key (e.g. for query parameters or HTTP headers).
func ConvertTableWithHeaderToStructSlice ¶
func ConvertTableWithHeaderToStructSlice(ctx context.Context, t *godog.Table, slicePtr interface{}) error
ConvertTableWithHeaderToStructSlice converts a godog table, where the first row is a header row, and the rest of rows are the values. For each column, the header value specifies the property in the struct (case insensitive). The first argument is the godog table, and the second one is a pointer to a slice of structs. The array is filled via reflection.
With the following example table:
Scenario: Table to struct test Given I configure my struct slice | Name | Value | | example 1 | 1 | | example 2 | 10 |
And the code:
scenCtx.Step(`^I configure my struct slice$`, func(table *godog.Table) error {
type TestElement struct {
Name string
Value int
}
testSlice := []TestElement{}
err := golium.ConvertTableWithHeaderToStructSlice(ctx, table, &testSlice)
})
It will be equivalent to:
testSlice := []TestElement{
TestElement{Name: "example 1", Value: 1},
TestElement{Name: "example 2", Value: 10},
}
func ConvertTableWithoutHeaderToStruct ¶
ConvertTableWithoutHeaderToStruct converts a godog table with two columns into a struct. The first column of the table corresponds to the struct property, and the seconds column to the value to be assigned.
With the following example table:
Scenario: Table to struct test Given I configure my struct | Name | 1 | | Value | example 1 |
And the code:
scenCtx.Step(`^I configure my struct$`, func(table *godog.Table) error {
type TestElement struct {
Name string
Value int
}
testElement := TestElement{}
err := golium.ConvertTableWithoutHeaderToStruct(ctx, table, &testElement)
})
It will be equivalent to:
testElement := TestElement{Name: "example 1", Value: 1}
Warning: still pending process values directly as arrays, i.e.: | addresses | ["http://localhost:8080"] |
use by now a CONF tag, i.e.: | addresses | [CONF:elasticsearch.addresses] |
func GetConfig ¶
GetConfig returns the golium configuration. This configuration includes relevant information as the environment or the directories for some assets or log files.
func InitializeContext ¶
InitializeContext adds the Context to the context. The new context is returned because context is immutable.
func Value ¶
Value converts a value as a string to consider some golium patterns. Supported patterns:
- Booleans: [TRUE] or [FALSE]
- Null value: [NULL]
- Empty value: [EMPTY]
- Number: [NUMBER:1234] or [NUMBER:1234.67]
- Configuration parameters: [CONF:test.parameter]
- Context values: [CTXT:test.context]
- SHA256: [SHA256:text.to.be.hashed]
- BASE64: [BASE64:text.to.be.base64.encoded]
- Time: [NOW:+24h:unix] with the format: [NOW:{duration}:{format}] The value {duration} can be empty (there is no change from now timestamp) or a format valid for time.ParseDuration function. Currently, it supports the following units: "ns", "us", "ms", "s", "m", "h". The format can be "unix" or a layout valid for time.Format function. It is possible to use [NOW]. In that case, it returns an int64 with the now timestamp in unix format.
Most cases, the return value is a string except for the following cases: - [TRUE] and [FALSE] return a bool type. - [NUMBER:1234] returns a float64 if s only contains this tag and there is no surrounding text. - [NOW:{duration}:{format}] returns an int64 when {format} is "unix".
func ValueAsInt ¶
ValueAsInt invokes Value and converts the return value to int.
Types ¶
type ComposedTag ¶
type ComposedTag struct {
// contains filtered or unexported fields
}
ComposedTag is a composition of tags, including StringTags, NamedTags and other ComposedTags to provide an evaluation.
func (ComposedTag) Value ¶
func (t ComposedTag) Value(ctx context.Context) interface{}
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context contains the context required for common utilities. It contains a map[string]interface{} to store global values and find them with [CTXT:xxx] tag.
func GetContext ¶
GetContext returns the Context stored in context. Note that the context should be previously initialized with InitializeContext function.
type ContextKey ¶
type ContextKey string
ContextKey defines a type to store the Context in context.Context.
type Launcher ¶
type Launcher struct {
}
Launcher is responsible to launch golium (based on godog). The default configuration is merged with environment variables.
func NewLauncherWithYaml ¶
NewLauncherWithYaml with a configuration from a yaml file. The yaml file is merged with environment variables.
type Map ¶
Map is an interface to get elements from a data structure with a dot notation.
func GetEnvironment ¶
func GetEnvironment() Map
GetEnvironment returns the environment configuration.
func NewMapFromJSONBytes ¶
NewMapFromJSONBytes creates a Map from a slice of bytes of a JSON document.
type NamedTag ¶
type NamedTag struct {
// contains filtered or unexported fields
}
NamedTag is a Tag that can be evaluated with a tag function depending on the name of the tag.
type StepsInitializer ¶
type StepsInitializer interface {
// InitializeSteps initializes a set of steps (e.g. http steps) to make them available
// but using a context.
InitializeSteps(ctx context.Context, scenCtx *godog.ScenarioContext) context.Context
}
StepsInitializer is an interface to initialize the steps in godog, but extending godog initializer with a context.
type StringTag ¶
type StringTag struct {
// contains filtered or unexported fields
}
StringTag represents a implicit tag composed of a text. This tag is used to compose a string with a tag to generate a new string.
type Tag ¶
Tag interface to calculate the value of a tag. A golium tag is a text surrounded by brackets that can be evaluated into a value. For example: [CONF:property]
func NewStringTag ¶
NewStringTag creates a Tag that evaluated to the string without any modification.