testservices

package
v0.0.0-...-921a65a Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testservices contains fake services used for unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src, dest string) error

Copy simulates the gsutil copy.

Types

type GetResponse

type GetResponse struct {
	Res string
	Err error
}

StatResponse represents a response tuple for a Stat function call.

type ReadDirResponse

type ReadDirResponse struct {
	Res []os.FileInfo
	Err error
}

ReadDirResponse represents a response tuple for a ReadDir function call.

type ReadFileResponse

type ReadFileResponse struct {
	Res []byte
	Err error
}

ReadDirResponse represents a response tuple for a ReadFile function call.

type StatResponse

type StatResponse struct {
	Res os.FileInfo
	Err error
}

StatResponse represents a response tuple for a Stat function call.

type TempDirResponse

type TempDirResponse struct {
	Dir string
	Err error
}

TempDirResponse represents a response tuple for a TempDir function call.

type TestFileInfo

type TestFileInfo struct {
	// Embed this so we only need to add methods used by testable functions
	os.FileInfo
	BaseName    string
	IsDirectory bool
}

TestFileInfo implements the os.FileInfo interface.

func (*TestFileInfo) IsDir

func (fi *TestFileInfo) IsDir() bool

IsDir returns true if the file is a directory.

func (*TestFileInfo) Name

func (fi *TestFileInfo) Name() string

type TestGcloud

type TestGcloud struct {
	ContainerClustersGetCredentialsErr error

	ConfigGetValueResp string
	ConfigGetValueErr  error
}

TestGcloud implements the GcloudService interface.

func (*TestGcloud) ConfigGetValue

func (g *TestGcloud) ConfigGetValue(ctx context.Context, property string) (string, error)

ConfigGetValue calls `gcloud config get-value <property>` and returns stdout.

func (*TestGcloud) ContainerClustersGetCredentials

func (g *TestGcloud) ContainerClustersGetCredentials(ctx context.Context, clusterName, clusterLocation, clusterProject string) error

ContainerClustersGetCredentials calls `gcloud container clusters get-credentials <clusterName> --zone=<clusterLocation> --project=<clusterProject>`.

func (*TestGcloud) ContainerClustersGetCredentialsGoClient

func (g *TestGcloud) ContainerClustersGetCredentialsGoClient(ctx context.Context, clusterName, clusterLocation, clusterProject string) error

ContainerClustersGetCredentialsGoClient calls `gcloud container clusters get-credentials <clusterName> --zone=<clusterLocation> --project=<clusterProject>`.

type TestGcsService

type TestGcsService struct {
	CopyResponse map[string]func(src, dst string) error
}

func (*TestGcsService) Copy

func (s *TestGcsService) Copy(ctx context.Context, src, dst string, recursive bool) error

type TestImage

type TestImage struct {
	// Embed this so we only need to add methods used by testable functions
	v1.Image
	Hash v1.Hash
	Err  error
}

TestImage simplements the v1.Image interface.

func (TestImage) Digest

func (i TestImage) Digest() (v1.Hash, error)

Digest returns the sha256 of this image's manifest.

type TestKubectl

type TestKubectl struct {
	ApplyResponse           map[string][]error
	ApplyFromStringResponse map[string][]error
	GetResponse             map[string]map[string][]GetResponse
}

TestKubectl implements the KubectlService interface.

func (*TestKubectl) Apply

func (k *TestKubectl) Apply(ctx context.Context, filename, namespace string) error

Apply calls `kubectl apply -f <filename> -n <namespace>`.

func (*TestKubectl) ApplyFromString

func (k *TestKubectl) ApplyFromString(ctx context.Context, configString, namespace string) error

ApplyFromString calls `kubectl apply -f - -n <namespace> < ${configString}`.

func (*TestKubectl) Get

func (k *TestKubectl) Get(ctx context.Context, kind, name, namespace, format string, ignoreNotFound bool) (string, error)

Get calls `kubectl get <kind> <name> -n <namespace> --output=<format>`.

type TestOS

type TestOS struct {
	StatResponse      map[string]StatResponse
	ReadDirResponse   map[string]ReadDirResponse
	ReadFileResponse  map[string]ReadFileResponse
	WriteFileResponse map[string]error
	MkdirAllResponse  map[string]error
	RemoveAllResponse map[string]error
	TempDirResponse   map[string]TempDirResponse
}

TestOS implements the OSService interface.

func (*TestOS) MkdirAll

func (o *TestOS) MkdirAll(ctx context.Context, dirname string, perm os.FileMode) error

MkdirAll creates a directory dirname, including all parent directories if they do not exist.

func (*TestOS) ReadDir

func (o *TestOS) ReadDir(ctx context.Context, dirname string) ([]os.FileInfo, error)

ReadDir gets file descriptions for all files contained in a directory dirname.

func (*TestOS) ReadFile

func (o *TestOS) ReadFile(ctx context.Context, filename string) ([]byte, error)

ReadFile gets the entire contents of a file filename as bytes.

func (*TestOS) RemoveAll

func (o *TestOS) RemoveAll(ctx context.Context, path string) error

RemoveAll removes path and any children it contains.

func (*TestOS) Stat

func (o *TestOS) Stat(ctx context.Context, filename string) (os.FileInfo, error)

Stat gets a file description for a file filename.

func (*TestOS) TempDir

func (o *TestOS) TempDir(ctx context.Context, dir, pattern string) (string, error)

TempDir creates a new temporary directory in the directory dir.

func (*TestOS) WriteFile

func (o *TestOS) WriteFile(ctx context.Context, filename string, data []byte, perm os.FileMode) error

WriteFile writes data to a file.

type TestRemote

type TestRemote struct {
	ImageResp v1.Image
	ImageErr  error
}

TestRemote implements the RemoteService interface.

func (*TestRemote) Image

func (r *TestRemote) Image(ctx context.Context, ref name.Reference) (v1.Image, error)

Image gets a remote image from a reference.

Jump to

Keyboard shortcuts

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