sanity

package
v0.3.0-1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

README

CSI Driver Sanity Tester

This library provides a simple way to ensure that a CSI driver conforms to the CSI specification. There are two ways to leverage this testing framework. For CSI drivers written in Golang, the framework provides a simple API function to call to test the driver. Another way to run the test suite is to use the command line program csi-sanity.

For Golang CSI Drivers

This framework leverages the Ginkgo BDD testing framework to deliver a descriptive test suite for your driver. To test your driver, simply call the API in one of your Golang TestXXX functions. For example:

func TestMyDriver(t *testing.T) {
	// Setup the full driver and its environment
	... setup driver ...
	config := &sanity.Config{
		TargetPath:     ...
		StagingPath:    ...
		Address:        endpoint,
	}


	// Now call the test suite
	sanity.Test(t, config)
}

Only one such test function is supported because under the hood a Ginkgo test suite gets constructed and executed by the call.

Alternatively, the tests can also be embedded inside a Ginkgo test suite. In that case it is possible to define multiple tests with different configurations:

var _ = Describe("MyCSIDriver", func () {
	Context("Config A", func () {
		var config &sanity.Config

		BeforeEach() {
			... setup driver and config...
		}

		AfterEach() {
			...tear down driver...
		}

		Describe("CSI sanity", func() {
			sanity.GinkgoTest(config)
		})
	})

	Context("Config B", func () {
		...
	})
})

Command line program

Please see csi-sanity

Documentation

Index

Constants

View Source
const (
	// DefTestVolumeSize defines the base size of dynamically
	// provisioned volumes. 10GB by default, can be overridden by
	// setting Config.TestVolumeSize.
	DefTestVolumeSize int64 = 10 * 1024 * 1024 * 1024
)

Variables

This section is empty.

Functions

func DescribeSanity

func DescribeSanity(text string, body func(*SanityContext)) bool

DescribeSanity must be used instead of the usual Ginkgo Describe to register a test block. The difference is that the body function will be called multiple times with the right context (when setting up a Ginkgo suite or a testing.T test, with the right configuration).

func GinkgoTest

func GinkgoTest(reqConfig *Config)

func MakeCreateSnapshotReq

func MakeCreateSnapshotReq(sc *SanityContext, name, sourceVolumeId string, parameters map[string]string) *csi.CreateSnapshotRequest

func MakeCreateVolumeReq

func MakeCreateVolumeReq(sc *SanityContext, name string) *csi.CreateVolumeRequest

func MakeDeleteSnapshotReq

func MakeDeleteSnapshotReq(sc *SanityContext, id string) *csi.DeleteSnapshotRequest

func MakeDeleteVolumeReq

func MakeDeleteVolumeReq(sc *SanityContext, id string) *csi.DeleteVolumeRequest

func Test

func Test(t *testing.T, reqConfig *Config)

Test will test the CSI driver at the specified address by setting up a Ginkgo suite and running it.

func TestVolumeSize

func TestVolumeSize(sc *SanityContext) int64

Types

type CSISecrets

type CSISecrets struct {
	CreateVolumeSecret              map[string]string `yaml:"CreateVolumeSecret"`
	DeleteVolumeSecret              map[string]string `yaml:"DeleteVolumeSecret"`
	ControllerPublishVolumeSecret   map[string]string `yaml:"ControllerPublishVolumeSecret"`
	ControllerUnpublishVolumeSecret map[string]string `yaml:"ControllerUnpublishVolumeSecret"`
	NodeStageVolumeSecret           map[string]string `yaml:"NodeStageVolumeSecret"`
	NodePublishVolumeSecret         map[string]string `yaml:"NodePublishVolumeSecret"`
	CreateSnapshotSecret            map[string]string `yaml:"CreateSnapshotSecret"`
	DeleteSnapshotSecret            map[string]string `yaml:"DeleteSnapshotSecret"`
}

CSISecrets consists of secrets used in CSI credentials.

type Config

type Config struct {
	TargetPath     string
	StagingPath    string
	Address        string
	SecretsFile    string
	TestVolumeSize int64
}

Config provides the configuration for the sanity tests. It needs to be initialized by the user of the sanity package.

type SanityContext

type SanityContext struct {
	Config  *Config
	Conn    *grpc.ClientConn
	Secrets *CSISecrets
}

SanityContext holds the variables that each test can depend on. It gets initialized before each test block runs.

Jump to

Keyboard shortcuts

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