testutils

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: Apache-2.0 Imports: 25 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 = ""

Variables

View Source
var InRule1, InRule2, EgressRule1, EgressRule2 apiv3.Rule
View Source
var MatchResource = Resource

Another name for the same matcher (which reads better when checking a single item).

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 added in v1.1.1

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 HookLogrusForGinkgo

func HookLogrusForGinkgo()

func Resource

func Resource(kind, namespace, name string, spec interface{}, optionalDescription ...interface{}) *resourceMatcher

Types

type DatastoreType added in v1.2.0

type DatastoreType int
const (
	DatastoreEtcdV3 DatastoreType = 1 << iota
	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) CacheSnapshot

func (st *SyncerTester) CacheSnapshot() map[string]model.KVPair

CacheSnapshot returns a copy of the cache. The copy is made with the lock held.

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) ExpectPath

func (st *SyncerTester) ExpectPath(path string)

ExpectPath verifies that a KVPair with a specified path is in the cache.

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. The possible state changes are: WaitingForDatastore -> ResyncInProgress -> InSync -> WaitingForDatastore. ExpectStatusUpdate will panic if called with the same status twice in a row.

func (*SyncerTester) ExpectUpdates

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

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.

func (*SyncerTester) ExpectValueMatches

func (st *SyncerTester) ExpectValueMatches(k model.Key, match gomegatypes.GomegaMatcher)

ExpectDataMatch verifies that the KV in the cache exists and matches the GomegaMatcher.

func (*SyncerTester) GetCacheEntries

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

GetCacheEntries returns a slice of the current cache entries.

func (*SyncerTester) GetCacheKVPair

func (st *SyncerTester) GetCacheKVPair(k string) interface{}

GetCacheValue returns the value of the KVPair from the cache.

func (*SyncerTester) GetCacheValue

func (st *SyncerTester) GetCacheValue(k string) interface{}

GetCacheValue returns the value of the KVPair from the cache or nil if not present.

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