testbase

package
v0.0.0-...-14f7cec Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package testbase provides a unit test infrastructure and a mock AccountProvider.

Index

Constants

This section is empty.

Variables

View Source
var ExpGroups = []*accounts.Group{
	&accounts.Group{
		Name:    "group1",
		GID:     1000,
		Members: []string(nil),
	},
	&accounts.Group{
		Name:    "group2",
		GID:     1001,
		Members: []string{"user2", "user1"},
	},
}

ExpGoups is sample group data.

View Source
var ExpKeys = map[string][]string{
	"user1": []string{
		"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbfMeFT1HFEF4NUfGY1N5xV59DcUSD0wrQ+PLshX3zNseddAq0mPRs1+rLwzH53GFzJu7p9gO2tODz1HanSSVhPXN5GuMVBA/9fZCmSkcsU18v machine1",
		"ssh-rsa AAAAB3NzaC1yc2EAAAADvUTKEXOxhMCs2MGQyRe1hWfS1wqTuhskuFlw7+iyyvgw2KQDKfJod4DiyXQpNF5361PrfduTF/T5I+tanSSVhPXN5GuMVBA/9fZCmSkcsU18v machine2",
	},
	"user3": []string{
		"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbfMeFT1HFEF4NUfGY1N5xV59DcUSD0wrQ+p9gO2tODz1HanSSVhPXN5GuMVBA/9fZCmSkcsU18v machine3",
		"ssh-rsa AAAAB3NzaC1yc2EAAAADvUTKEXOxhMCs2MGQyRe1hWfS1wqTuhskuFlw7+iyyvgwuTF/T5I+tanSSVhPXN5GuMVBA/9fZCmSkcsU18v machine4",
	},
}

ExpKeys is sample key data.

View Source
var ExpNames = []string{"group1", "group2", "user1", "user2"}

ExpNames is sample name data.

View Source
var ExpUsers = []*accounts.User{
	&accounts.User{
		Name:          "user1",
		UID:           1001,
		GID:           1000,
		Gecos:         "John Doe",
		HomeDirectory: "/home/user1",
		Shell:         "/bin/bash",
	},
	&accounts.User{
		Name:          "user2",
		UID:           1002,
		GID:           1000,
		Gecos:         "Jane Doe",
		HomeDirectory: "/home/user2",
		Shell:         "/bin/zsh",
	},
}

ExpUsers is sample user data.

Functions

func RunCases

func RunCases(t *testing.T, cases []TestCase)

RunCases runs a set of test cases.

Types

type FailureCase

type FailureCase struct {
	Name string
	Call func() (interface{}, error)
	Exp  string
}

A FailureCase is a test case which is expected to return an error.

type MockProvider

type MockProvider struct {
	Err  error
	Usrs []*accounts.User
	Grps []*accounts.Group
	Nams []string
	Keys map[string][]string
}

A MockProvider is an AccountProvider used for testing.

func (*MockProvider) AuthorizedKeys

func (m *MockProvider) AuthorizedKeys(username string) ([]string, error)

AuthorizedKeys satisfies AccountProvider.

func (*MockProvider) GroupByGID

func (m *MockProvider) GroupByGID(gid uint32) (*accounts.Group, error)

GroupByGID satisfies AccountProvider.

func (*MockProvider) GroupByName

func (m *MockProvider) GroupByName(name string) (*accounts.Group, error)

GroupByName satisfies AccountProvider.

func (*MockProvider) Groups

func (m *MockProvider) Groups() ([]*accounts.Group, error)

Groups satisfies AccountProvider.

func (*MockProvider) IsName

func (m *MockProvider) IsName(name string) (bool, error)

IsName satisfies AccountProvider.

func (*MockProvider) Names

func (m *MockProvider) Names() ([]string, error)

Names satisfies AccountProvider.

func (*MockProvider) UserByName

func (m *MockProvider) UserByName(name string) (*accounts.User, error)

UserByName satisfies AccountProvider.

func (*MockProvider) UserByUID

func (m *MockProvider) UserByUID(uid uint32) (*accounts.User, error)

UserByUID satisfies AccountProvider.

func (*MockProvider) Users

func (m *MockProvider) Users() ([]*accounts.User, error)

Users satisfies AccountProvider.

type SuccessCase

type SuccessCase struct {
	Name string
	Call func() (interface{}, error)
	Exp  interface{}
}

A SuccessCase is a test case which is expected to return successfully.

type TestCase

type TestCase interface {
	// contains filtered or unexported methods
}

A TestCase is any test case.

Jump to

Keyboard shortcuts

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