Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
FolderOrigin-RevId: /usr/local/google/home/gdennis/copybara/temp/folder-destination6384971181149566477/.
  • Loading branch information
GGN Engprod Team authored and greg-dennis committed Jan 31, 2023
1 parent 3b28896 commit 34623d2
Show file tree
Hide file tree
Showing 20 changed files with 59,349 additions and 53,692 deletions.
52 changes: 52 additions & 0 deletions eventlis/eventlis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023 Google LLC
//
// 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
//
// https://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.

// Package eventlis provides an event listener API.
package eventlis

import (
"github.com/openconfig/ondatra/binding"
"github.com/openconfig/ondatra/internal/events"
)

// EventListener is an event listener API.
type EventListener struct{}

// BeforeTestsEvent occurs after the reservation is complete and before tests
// start executing.
type BeforeTestsEvent struct {
Reservation *binding.Reservation
}

// AfterTestsEvent occurs after the tests are finished executing and before
// the reservation is released.
type AfterTestsEvent struct {
ExitCode *int
}

// AddBeforeTestsCallback adds a callback to run after the reservation is
// complete and before tests start executing.
func (el *EventListener) AddBeforeTestsCallback(cb func(*BeforeTestsEvent) error) {
events.AddBeforeTests(func(res *binding.Reservation) error {
return cb(&BeforeTestsEvent{Reservation: res})
})
}

// AddAfterTestsCallback adds a callback to run after the tests are finished
// executing and before the reservation is released.
func (el *EventListener) AddAfterTestsCallback(cb func(*AfterTestsEvent) error) {
events.AddAfterTests(func(exitCode *int) error {
return cb(&AfterTestsEvent{ExitCode: exitCode})
})
}
6 changes: 6 additions & 0 deletions gnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func Lookup[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T]) *y
// Note: This is a workaround for Go's type inference not working for this use case and may be removed in a subsequent release.
// Note: This is equivalent to calling Lookup with a ConfigQuery and providing a fully-qualified type parameter.
func LookupConfig[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.ConfigQuery[T]) *ygnmi.Value[T] {
t.Helper()
return Lookup[T](t, dev, q)
}

Expand All @@ -137,6 +138,7 @@ func Get[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T]) T {
// Note: This is a workaround for Go's type inference not working for this use case and may be removed in a subsequent release.
// Note: This is equivalent to calling Get with a ConfigQuery and providing a fully-qualified type parameter.
func GetConfig[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.ConfigQuery[T]) T {
t.Helper()
return Get[T](t, dev, q)
}

Expand Down Expand Up @@ -193,6 +195,7 @@ func (w *Watcher[T]) Cancel() {
// to complete. It returns the last observed value and a boolean that indicates whether
// that value satisfies the predicate.
func Watch[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T], timeout time.Duration, pred func(*ygnmi.Value[T]) bool) *Watcher[T] {
t.Helper()
c := newClient(t, dev, "Watch")
ctx, cancel := context.WithTimeout(createContext(dev), timeout)
w := ygnmi.Watch(ctx, c, q, func(v *ygnmi.Value[T]) error {
Expand Down Expand Up @@ -256,6 +259,7 @@ func (c *Collector[T]) Await(t testing.TB) []*ygnmi.Value[T] {
// Collect starts an asynchronous collection of the values at the query with a STREAM subscription.
// Calling Await on the return Collection waits until the timeout is reached and returns the collected values.
func Collect[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T], timeout time.Duration) *Collector[T] {
t.Helper()
c := newClient(t, dev, "Collect")
ctx, cancel := context.WithTimeout(createContext(dev), timeout)
collect := &Collector[T]{
Expand Down Expand Up @@ -299,6 +303,7 @@ func GetAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T]) []T
// to complete. It returns the last observed value and a boolean that indicates whether
// that value satisfies the predicate.
func WatchAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T], timeout time.Duration, pred func(*ygnmi.Value[T]) bool) *Watcher[T] {
t.Helper()
c := newClient(t, dev, "WatchAll")
ctx, cancel := context.WithTimeout(createContext(dev), timeout)
w := ygnmi.WatchAll(ctx, c, q, func(v *ygnmi.Value[T]) error {
Expand All @@ -318,6 +323,7 @@ func WatchAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T], t
// CollectAll starts an asynchronous collection of the values at the query with a STREAM subscription.
// Calling Await on the return Collection waits until the timeout is reached and returns the collected values.
func CollectAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T], timeout time.Duration) *Collector[T] {
t.Helper()
c := newClient(t, dev, "CollectAll")
ctx, cancel := context.WithTimeout(createContext(dev), timeout)
collect := &Collector[T]{
Expand Down
Loading

0 comments on commit 34623d2

Please sign in to comment.