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.
Index ¶
- Constants
- Variables
- func CreateRule(ipv, icmpType, icmpCode int, ...) (api.Rule, api.Rule)
- func DeleteNamespace(client *kubernetes.Clientset, name string)
- func E2eDatastoreDescribe(description string, datastores DatastoreType, ...) bool
- func GetK8sInlineConfig() apiconfig.CalicoAPIConfig
- func HookLogrusForGinkgo()
- func Resource(kind, namespace, name string, spec interface{}, ...) *resourceMatcher
- func ResourceWithStatus(kind, namespace, name string, spec, status interface{}, ...) *resourceMatcher
- type CacheEntry
- type DatastoreType
- type SyncerTester
- func (st *SyncerTester) BlockUpdateHandling()
- func (st *SyncerTester) CacheSnapshot() map[string]CacheEntry
- func (st *SyncerTester) DefaultSanitizer(updates []api.Update) []api.Update
- func (st *SyncerTester) ExpectCacheSize(size int)
- func (st *SyncerTester) ExpectData(kvp model.KVPair)
- func (st *SyncerTester) ExpectNoData(k model.Key)
- func (st *SyncerTester) ExpectOnUpdates(expected [][]api.Update)
- func (st *SyncerTester) ExpectParseError(key, value string)
- func (st *SyncerTester) ExpectPath(path string)
- func (st *SyncerTester) ExpectStatusUnchanged()
- func (st *SyncerTester) ExpectStatusUpdate(status api.SyncStatus, timeout ...time.Duration)
- func (st *SyncerTester) ExpectUpdates(expectedUpdates []api.Update, checkOrder bool, ...)
- func (st *SyncerTester) ExpectValueMatches(k model.Key, match gomegatypes.GomegaMatcher)
- func (st *SyncerTester) GetCacheEntries() []model.KVPair
- func (st *SyncerTester) GetCacheKVPair(k string) *model.KVPair
- func (st *SyncerTester) GetCacheValue(k string) interface{}
- func (st *SyncerTester) OnStatusUpdated(status api.SyncStatus)
- func (st *SyncerTester) OnUpdates(updates []api.Update)
- func (st *SyncerTester) ParseFailed(rawKey string, rawValue string)
- func (st *SyncerTester) UnblockUpdateHandling()
- type TestResourceWatchInterface
Constants ¶
const ExpectNoNamespace = ""
Variables ¶
var InRule1, InRule2, EgressRule1, EgressRule2 apiv3.Rule
var MatchResource = Resource
Another name for the same matcher (which reads better when checking a single item).
var MatchResourceWithStatus = ResourceWithStatus
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 GetK8sInlineConfig ¶
func GetK8sInlineConfig() apiconfig.CalicoAPIConfig
GetK8sInlineConfig returns a CalicoAPIConfig with the kubeconfig inline.
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 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.