config

package
v2.14.5 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() string

func DataDir

func DataDir() string

func HomeDirPath

func HomeDirPath(subdir string) (string, error)

func StateDir

func StateDir() string

func StubWriteConfig

func StubWriteConfig(t *testing.T) func(io.Writer, io.Writer)

StubWriteConfig stubs out the filesystem where config file are written. It then returns a function that will read in the config files into io.Writers. It automatically cleans up environment variables and written files.

Types

type AliasConfig

type AliasConfig struct {
	// contains filtered or unexported fields
}

func (*AliasConfig) Add

func (a *AliasConfig) Add(alias, expansion string)

func (*AliasConfig) All

func (a *AliasConfig) All() map[string]string

func (*AliasConfig) Delete

func (a *AliasConfig) Delete(alias string) error

func (*AliasConfig) Get

func (a *AliasConfig) Get(alias string) (string, error)

type Config

type Config interface {
	AuthToken(string) (string, string)
	Get(string, string) (string, error)
	GetOrDefault(string, string) (string, error)
	Set(string, string, string)
	UnsetHost(string)
	Hosts() []string
	DefaultHost() (string, string)
	Aliases() *AliasConfig
	Write() error
}

This interface describes interacting with some persistent configuration for gh.

func NewConfig

func NewConfig() (Config, error)

type ConfigMock added in v2.14.0

type ConfigMock struct {
	// AliasesFunc mocks the Aliases method.
	AliasesFunc func() *AliasConfig

	// AuthTokenFunc mocks the AuthToken method.
	AuthTokenFunc func(s string) (string, string)

	// DefaultHostFunc mocks the DefaultHost method.
	DefaultHostFunc func() (string, string)

	// GetFunc mocks the Get method.
	GetFunc func(s1 string, s2 string) (string, error)

	// GetOrDefaultFunc mocks the GetOrDefault method.
	GetOrDefaultFunc func(s1 string, s2 string) (string, error)

	// HostsFunc mocks the Hosts method.
	HostsFunc func() []string

	// SetFunc mocks the Set method.
	SetFunc func(s1 string, s2 string, s3 string)

	// UnsetHostFunc mocks the UnsetHost method.
	UnsetHostFunc func(s string)

	// WriteFunc mocks the Write method.
	WriteFunc func() error
	// contains filtered or unexported fields
}

ConfigMock is a mock implementation of Config.

func TestSomethingThatUsesConfig(t *testing.T) {

	// make and configure a mocked Config
	mockedConfig := &ConfigMock{
		AliasesFunc: func() *AliasConfig {
			panic("mock out the Aliases method")
		},
		AuthTokenFunc: func(s string) (string, string) {
			panic("mock out the AuthToken method")
		},
		DefaultHostFunc: func() (string, string) {
			panic("mock out the DefaultHost method")
		},
		GetFunc: func(s1 string, s2 string) (string, error) {
			panic("mock out the Get method")
		},
		GetOrDefaultFunc: func(s1 string, s2 string) (string, error) {
			panic("mock out the GetOrDefault method")
		},
		HostsFunc: func() []string {
			panic("mock out the Hosts method")
		},
		SetFunc: func(s1 string, s2 string, s3 string)  {
			panic("mock out the Set method")
		},
		UnsetHostFunc: func(s string)  {
			panic("mock out the UnsetHost method")
		},
		WriteFunc: func() error {
			panic("mock out the Write method")
		},
	}

	// use mockedConfig in code that requires Config
	// and then make assertions.

}

func NewBlankConfig

func NewBlankConfig() *ConfigMock

func NewFromString

func NewFromString(cfgStr string) *ConfigMock

func (*ConfigMock) Aliases added in v2.14.0

func (mock *ConfigMock) Aliases() *AliasConfig

Aliases calls AliasesFunc.

func (*ConfigMock) AliasesCalls added in v2.14.0

func (mock *ConfigMock) AliasesCalls() []struct {
}

AliasesCalls gets all the calls that were made to Aliases. Check the length with:

len(mockedConfig.AliasesCalls())

func (*ConfigMock) AuthToken added in v2.14.0

func (mock *ConfigMock) AuthToken(s string) (string, string)

AuthToken calls AuthTokenFunc.

func (*ConfigMock) AuthTokenCalls added in v2.14.0

func (mock *ConfigMock) AuthTokenCalls() []struct {
	S string
}

AuthTokenCalls gets all the calls that were made to AuthToken. Check the length with:

len(mockedConfig.AuthTokenCalls())

func (*ConfigMock) DefaultHost added in v2.14.0

func (mock *ConfigMock) DefaultHost() (string, string)

DefaultHost calls DefaultHostFunc.

func (*ConfigMock) DefaultHostCalls added in v2.14.0

func (mock *ConfigMock) DefaultHostCalls() []struct {
}

DefaultHostCalls gets all the calls that were made to DefaultHost. Check the length with:

len(mockedConfig.DefaultHostCalls())

func (*ConfigMock) Get added in v2.14.0

func (mock *ConfigMock) Get(s1 string, s2 string) (string, error)

Get calls GetFunc.

func (*ConfigMock) GetCalls added in v2.14.0

func (mock *ConfigMock) GetCalls() []struct {
	S1 string
	S2 string
}

GetCalls gets all the calls that were made to Get. Check the length with:

len(mockedConfig.GetCalls())

func (*ConfigMock) GetOrDefault added in v2.14.0

func (mock *ConfigMock) GetOrDefault(s1 string, s2 string) (string, error)

GetOrDefault calls GetOrDefaultFunc.

func (*ConfigMock) GetOrDefaultCalls added in v2.14.0

func (mock *ConfigMock) GetOrDefaultCalls() []struct {
	S1 string
	S2 string
}

GetOrDefaultCalls gets all the calls that were made to GetOrDefault. Check the length with:

len(mockedConfig.GetOrDefaultCalls())

func (*ConfigMock) Hosts added in v2.14.0

func (mock *ConfigMock) Hosts() []string

Hosts calls HostsFunc.

func (*ConfigMock) HostsCalls added in v2.14.0

func (mock *ConfigMock) HostsCalls() []struct {
}

HostsCalls gets all the calls that were made to Hosts. Check the length with:

len(mockedConfig.HostsCalls())

func (*ConfigMock) Set added in v2.14.0

func (mock *ConfigMock) Set(s1 string, s2 string, s3 string)

Set calls SetFunc.

func (*ConfigMock) SetCalls added in v2.14.0

func (mock *ConfigMock) SetCalls() []struct {
	S1 string
	S2 string
	S3 string
}

SetCalls gets all the calls that were made to Set. Check the length with:

len(mockedConfig.SetCalls())

func (*ConfigMock) UnsetHost added in v2.14.0

func (mock *ConfigMock) UnsetHost(s string)

UnsetHost calls UnsetHostFunc.

func (*ConfigMock) UnsetHostCalls added in v2.14.0

func (mock *ConfigMock) UnsetHostCalls() []struct {
	S string
}

UnsetHostCalls gets all the calls that were made to UnsetHost. Check the length with:

len(mockedConfig.UnsetHostCalls())

func (*ConfigMock) Write added in v2.14.0

func (mock *ConfigMock) Write() error

Write calls WriteFunc.

func (*ConfigMock) WriteCalls added in v2.14.0

func (mock *ConfigMock) WriteCalls() []struct {
}

WriteCalls gets all the calls that were made to Write. Check the length with:

len(mockedConfig.WriteCalls())

type ConfigOption

type ConfigOption struct {
	Key           string
	Description   string
	DefaultValue  string
	AllowedValues []string
}

func ConfigOptions

func ConfigOptions() []ConfigOption

Jump to

Keyboard shortcuts

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