testutils

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 33 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.

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 MatchResourceWithStatus = ResourceWithStatus
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 DeleteNamespace

func DeleteNamespace(client *kubernetes.Clientset, name string)

DeleteNamespace deletes the namespace and waits for it to complete.

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 HookLogrusForGinkgo

func HookLogrusForGinkgo()

func Resource

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

func ResourceWithStatus

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

Types

type CacheEntry

type CacheEntry struct {
	model.KVPair
	Seen bool
}

type DatastoreType

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]CacheEntry

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

func (*SyncerTester) DefaultSanitizer

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

DefaultSanitizer provides a default filtering of the updates, used when comparing sets of updates. This filter removes updates for certain resource types that are updated outside of the test code. In addition, the update comparer (see updatesEqual and kvpsEqual) are careful to remove resource versions when comparing create/delete updates for the same resource types.

func (*SyncerTester) ExpectCacheSize

func (st *SyncerTester) ExpectCacheSize(size int)

ExpectCacheSize verifies that the cache size is as expected. If this fails, the entire cache is included in the logs - entries that were explicitly checked will be marked as `Seen: true`.

func (*SyncerTester) ExpectData

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

ExpectData verifies that a KVPair is in the cache. For instance specific data (such as revision, or creation timestamp) - those values are only compared if set in the supplied kvp. Important details such as name, namespace, type and value are always compared. This marks the cache entry as "Seen".

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)

ExpectOnUpdates tests 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. This will mark the cache entry as "Seen".

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, timeout ...time.Duration)

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(expectedUpdates []api.Update, checkOrder bool, sanitizer ...func(u []api.Update) []api.Update)

ExpectUpdates tests the onUpdate events. 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) *model.KVPair

GetCacheValue returns the value of the KVPair from the cache and flags the entry as "Seen". This makes debugging easier.

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