testutils

package
v0.0.0-...-bdd73da Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const ExpectNoNamespace = ""

ExpectResource is a test validation function that checks the specified resource matches the key attributes: kind, namespace, name and the supplied Spec. This should be called within a Ginkgo test.

Variables

View Source
var EgressRule1 = apiv2.Rule{
	Action:    "pass",
	IPVersion: &ipv4,
	Protocol:  &numProtocol1,
	ICMP:      &icmp1,
	Source: apiv2.EntityRule{
		Tag:      "tag3",
		Nets:     []string{cidr2},
		Selector: "all()",
	},
}
View Source
var EgressRule2 = apiv2.Rule{
	Action:    "allow",
	IPVersion: &ipv6,
	Protocol:  &strProtocol2,
	ICMP:      &icmp1,
	Source: apiv2.EntityRule{
		Tag:      "tag4",
		Nets:     []string{cidrv62},
		Selector: "label2 == '1234'",
	},
}
View Source
var InRule1 = apiv2.Rule{
	Action:    "allow",
	IPVersion: &ipv4,
	Protocol:  &strProtocol1,
	ICMP:      &icmp1,
	Source: apiv2.EntityRule{
		Tag:      "tag1",
		Nets:     []string{cidr1},
		Selector: "label1 == 'value1'",
		Ports: []numorstring.Port{
			portRange,
			singlePort,
			namedPort,
		},
	},
}
View Source
var InRule2 = apiv2.Rule{
	Action:    "deny",
	IPVersion: &ipv6,
	Protocol:  &numProtocol1,
	ICMP:      &icmp1,
	Source: apiv2.EntityRule{
		Tag:      "tag2",
		Nets:     []string{cidrv61},
		Selector: "has(label2)",
	},
}
View Source
var (
	UnsetSyncStatus = api.SyncStatus(255)
)

Functions

func CreateRule

func CreateRule(ipv, icmpType, icmpCode int, proto, cidrStr, tag, selector, inAction, eAction string) (api.Rule, api.Rule)

CreateRule takes all fields necessary to create a api.Rule object and returns ingress and egress api.Rules.

func E2eDatastoreDescribe

func E2eDatastoreDescribe(description string, datastores DatastoreType, body func(config apiconfig.CalicoAPIConfig)) bool

E2eDatastoreDescribe is a replacement for ginkgo.Describe which invokes Describe multiple times for one or more different datastore drivers - passing in the Calico API configuration as a parameter to the test function. This allows easy construction of end-to-end tests covering multiple different datastore drivers.

The *datastores* parameter is a bit-wise OR of the required datastore drivers that will be tested.

func ExpectResource

func ExpectResource(res runtime.Object, kind, namespace, name string, spec interface{}, optionalDescription ...interface{})

func HookLogrusForGinkgo

func HookLogrusForGinkgo()

Types

type DatastoreType

type DatastoreType int
const (
	DatastoreEtcdV2 DatastoreType = 1 << iota
	DatastoreEtcdV3
	DatastoreK8s

	DatastoreAll = DatastoreEtcdV3 | DatastoreK8s
)

type SyncerTester

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

func NewSyncerTester

func NewSyncerTester() *SyncerTester

Create a new SyncerTester. This helper class implements the api.SyncerCallbacks and provides a number of useful methods for asserting the data that has been supplied on the callbacks.

func (*SyncerTester) BlockUpdateHandling

func (st *SyncerTester) BlockUpdateHandling()

Block the update handling.

func (*SyncerTester) ExpectCacheSize

func (st *SyncerTester) ExpectCacheSize(size int)

ExpectCacheSize verifies that the cache size is as expected.

func (*SyncerTester) ExpectData

func (st *SyncerTester) ExpectData(kvp model.KVPair)

ExpectData verifies that a KVPair is in the cache. If a Revision is not supplied, then just the value will be compared (useful for Kubernetes node backed resources where the revision number is not stable).

func (*SyncerTester) ExpectNoData

func (st *SyncerTester) ExpectNoData(k model.Key)

ExpectNoData verifies that a Key is not in the cache.

func (*SyncerTester) ExpectOnUpdates

func (st *SyncerTester) ExpectOnUpdates(expected [][]api.Update)

Call to test which onUpdate events were received. This removes all updates/onUpdate events from this receiver, so that the next call to this just requires the next set of updates.

Note that for this function to be useful, your test code needs to have fine grained control over the order in which events occur.

func (*SyncerTester) ExpectParseError

func (st *SyncerTester) ExpectParseError(key, value string)

Call to test the next parse error that we expect to have received. This removes the parse error from the receiver.

func (*SyncerTester) ExpectStatusUnchanged

func (st *SyncerTester) ExpectStatusUnchanged()

ExpectStatusUnchanged verifies that the status has not changed since the last ExpectStatusUpdate call.

func (*SyncerTester) ExpectStatusUpdate

func (st *SyncerTester) ExpectStatusUpdate(status api.SyncStatus)

ExpectStatusUpdate verifies a status update message has been received. This should only be called *after* a new status change has occurred. Since the concrete implementations of the syncer API only migrate status in increasing readiness, this means it should be called once each for the following statuses in order: WaitingForDatastore, ResyncInProgress, InSync. The OnStatusUpdate callback will panic if the above is not true.

func (*SyncerTester) ExpectUpdates

func (st *SyncerTester) ExpectUpdates(expected []api.Update)

Call to test the onUpdate events (without worrying about which specific OnUpdate events were received). This removes all updates/onUpdate events from this receiver, so that the next call to this just requires the next set of updates.

Note that for this function to be useful, your test code needs to have fine grained control over the order in which events occur.

func (*SyncerTester) GetCacheEntries

func (st *SyncerTester) GetCacheEntries() []model.KVPair

GetCacheEntries returns a slice of the current cache entries.

func (*SyncerTester) OnStatusUpdated

func (st *SyncerTester) OnStatusUpdated(status api.SyncStatus)

OnStatusUpdated updates the current status and then blocks until a call to ExpectStatusUpdate() has been called.

func (*SyncerTester) OnUpdates

func (st *SyncerTester) OnUpdates(updates []api.Update)

OnUpdates just stores the update and asserts the state of the cache and the update.

func (*SyncerTester) ParseFailed

func (st *SyncerTester) ParseFailed(rawKey string, rawValue string)

ParseFailed just stores the parse failure.

func (*SyncerTester) UnblockUpdateHandling

func (st *SyncerTester) UnblockUpdateHandling()

Unblock the update handling.

type TestResourceWatchInterface

type TestResourceWatchInterface interface {
	// Stop is used to free up resources associated with the test watcher.  The caller
	// must call this when they are finished with the watcher.
	Stop()

	// ExpectEvents is used to validate the events received by the Watcher match the
	// set of expected events.
	ExpectEvents(kind string, events []watch.Event)

	// ExpectEventsAnyOrder is used to validate the events received by the Watcher match the
	// set of expected events.  The order of events is not important.  This should only be
	// called with sets of added events (not deleted or modified), and is used to verify an
	// initial snapshot.
	ExpectEventsAnyOrder(kind string, events []watch.Event)
}

TestResourceWatchInterface provides methods to terminate a resource watch test, and to validate the events received by the Watch.

func NewTestResourceWatch

func NewTestResourceWatch(datastoreType apiconfig.DatastoreType, w watch.Interface) TestResourceWatchInterface

TestResourceWatch is a test helper used to validate a set of events are received from a watcher. The caller creates a watch.Interface from the resource-specific client and passes that to TestResourceWatch to create a TestResourceWatchInterface.

Jump to

Keyboard shortcuts

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