config

package
v0.0.0-...-b93a6bd Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config contains the structures, flags, and parsing of the cbtest configuration. Note that configuration is optional, and can be passed either using a config file or command line flags (with the latter taking precedence over the former).

Configuration file

A minimal configuration file looks like follows:

{
  "platformUrl": "https://INSTANCE.clearblade.com",
  "messagingUrl": "INSTANCE.clearblade.com:1883",
  "registrationKey": "some-registration-key",
  "systemKey": "abc123abc123abc123abc123abc123",
  "systemSecret": "ABC123ABC123ABC123ABC123ABC123",
  "developer": {
    "email": "some-email@email.com",
    "password": "some-password"
  }
}

Flags

Since cbtest integrates with go test, flags can be specified as follows:

go test -v <PATH-TO-TEST> -args -cbtest.config <PATH-TO-CONFIG> [-cbtest.*]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigOut

func ConfigOut() string

ConfigOut returns the value given to the `-cbtest.config-out` flag.

func ConfigPath

func ConfigPath() string

ConfigPath returns the value given to the `-cbtest.config` flag.

func DeveloperEmail

func DeveloperEmail() string

DeveloperEmail returns the value given to the `-cbtest.dev-email` flag.

func DeveloperPassword

func DeveloperPassword() string

DeveloperPassword returns the value given to the `-cbtest.dev-password` flag.

func DeviceActiveKey

func DeviceActiveKey() string

DeviceActiveKey returns the value given to the `-cbtest.device-active-key` flag.

func DeviceName

func DeviceName() string

DeviceName returns the value given to the `-cbtest.device-name` flag.

func FlagFound

func FlagFound(name string) bool

FlagFound returns true if the flag with the given name was explicitly passed.

func HasConfig

func HasConfig() bool

HasConfig returns true if a config path was provided.

func HasConfigOut

func HasConfigOut() bool

HasConfigOut returns true if the user passed the `-cbtest.config-out` flag.

func MessagingURL

func MessagingURL() string

MessagingURL returns the value given to the `-cbtest.messaging-url` flag.

func PlatformURL

func PlatformURL() string

PlatformURL returns the value given to the `-cbtest.platform-url` flag.

func RegistrationKey

func RegistrationKey() string

RegistrationKey returns the value given to the `-cbtest.registration-key` flag.

func SaveConfig

func SaveConfig(t cbtest.T, c *Config) (string, error)

SaveConfig saves the config to disk. It uses either (1) the config Out field if provided, or (2) a default path constructed from the given test object. Returns the output path and an error (if any).

func ShouldImportRows

func ShouldImportRows() bool

ShouldImportRows returns the value given to the `-cbtest.import-rows` flag.

func ShouldImportUsers

func ShouldImportUsers() bool

ShouldImportUsers returns the value given to the `-cbtest.import-users` flag.

func SystemKey

func SystemKey() string

SystemKey returns the value given to the `-cbtest.system-key` flag.

func SystemSecret

func SystemSecret() string

SystemSecret returns the value given to the `-cbtest.system-secret` flag.

func UserEmail

func UserEmail() string

UserEmail returns the value given to the `-cbtest.user-email` flag.

func UserPassword

func UserPassword() string

UserPassword returns the value given to the `-cbtest.user-password` flag.

func WriteConfig

func WriteConfig(w io.Writer, c *Config) error

WriteConfig writes the config to the given writer.

func WriteConfigToPath

func WriteConfigToPath(path string, c *Config) error

WriteConfigToPath writes the config to the given path.

Types

type Config

type Config struct {
	PlatformURL     string     `json:"platformUrl" mapstructure:"platformUrl"`
	MessagingURL    string     `json:"messagingUrl" mapstructure:"messagingUrl"`
	RegistrationKey string     `json:"registrationKey,omitempty" mapstructure:"registrationKey"`
	SystemKey       string     `json:"systemKey,omitempty" mapstructure:"systemKey"`
	SystemSecret    string     `json:"systemSecret,omitempty" mapstructure:"systemSecret"`
	Developer       *Developer `json:"developer,omitempty" mapstructure:"developer"`
	User            *User      `json:"user,omitempty" mapstructre:"user"`
	Device          *Device    `json:"device,omitempty" mapstructure:"device"`
	Import          *Import    `json:"import,omitempty" mapstructure:"import"`
	Out             string     `json:"-" mapstructure:"-"`
}

Config contains information about the system that is gonna be used for testing.

func GetDefaultConfig

func GetDefaultConfig() *Config

GetDefaultConfig returns a new *Config instance with default values.

func ObtainConfig

func ObtainConfig(t cbtest.T) (*Config, error)

ObtainConfig returns the config that is gonna be used by cbtest. It uses either (1) default config, or (2) config read from the config path flag. Final values in the config are overridden by those provided in the flags.

func ReadConfig

func ReadConfig(r io.Reader) (*Config, error)

ReadConfig reads the config from the given reader.

func ReadConfigFromPath

func ReadConfigFromPath(path string) (*Config, error)

ReadConfigFromPath reads the config from the given path.

func (*Config) Config

func (c *Config) Config(cbtest.T) *Config

Config returns a *Config instance.

func (*Config) HasDeveloper

func (c *Config) HasDeveloper() bool

HasDeveloper returns true if the given config has developer information.

func (*Config) HasDevice

func (c *Config) HasDevice() bool

HasDevice returns true if the given config has device information.

func (*Config) HasSystem

func (c *Config) HasSystem() bool

HasSystem returns true if the given config has system information.

func (*Config) HasUser

func (c *Config) HasUser() bool

HasUser returns true if the given config has user information.

func (*Config) ShouldSave

func (c *Config) ShouldSave() bool

ShouldSave returns true if the out field of config is not empty (meaning the user to save the config to the specified path).

type Developer

type Developer struct {
	Email    string `json:"email" mapstructure:"email"`
	Password string `json:"password" mapstructure:"password"`
}

Developer contains the developer credentials that must be provided if using an existing system.

type Device

type Device struct {
	Name      string `json:"name" mapstructure:"name"`
	ActiveKey string `json:"activeKey" mapstructure:"activeKey"`
}

Device contains the credentials for a device in the system.

type Import

type Import struct {
	ImportUsers bool `json:"importUsers" mapstructure:"importUsers"`
	ImportRows  bool `json:"importRows" mapstructure:"importRows"`
}

Import contains import configuration values.

type User

type User struct {
	Email    string `json:"email" mapstructure:"email"`
	Password string `json:"password" mapstructure:"password"`
}

User contains the credentials for an user in the system.

Jump to

Keyboard shortcuts

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