mirror of https://github.com/hashicorp/boundary
refactor (events): QOL fix: turn off events for tests. (#3163)
parent
8c265bf7c1
commit
a4f54cb98f
@ -0,0 +1,58 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
// getOpts - iterate the inbound Options and return a struct
|
||||
func getOpts(opt ...Option) options {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
o(&opts)
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
// Option - how Options are passed as arguments
|
||||
type Option func(*options)
|
||||
|
||||
// options = how options are represented
|
||||
type options struct {
|
||||
withSysEventsEnabled bool
|
||||
withAuditEventsEnabled bool
|
||||
withObservationsEnabled bool
|
||||
testWithErrorEventsEnabled bool
|
||||
}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
return options{}
|
||||
}
|
||||
|
||||
// WithSysEventsEnabled provides an option for enabling system events
|
||||
func WithSysEventsEnabled(enable bool) Option {
|
||||
return func(o *options) {
|
||||
o.withSysEventsEnabled = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithAuditEventsEnabled provides an option for enabling audit events
|
||||
func WithAuditEventsEnabled(enable bool) Option {
|
||||
return func(o *options) {
|
||||
o.withAuditEventsEnabled = enable
|
||||
}
|
||||
}
|
||||
|
||||
// WithObservationsEnabled provides an option for enabling observation events
|
||||
func WithObservationsEnabled(enable bool) Option {
|
||||
return func(o *options) {
|
||||
o.withObservationsEnabled = enable
|
||||
}
|
||||
}
|
||||
|
||||
// TestWithErrorEventsEnabled provides an option for enabling error events
|
||||
// during tests.
|
||||
func TestWithErrorEventsEnabled(_ testing.TB, enable bool) Option {
|
||||
return func(o *options) {
|
||||
o.testWithErrorEventsEnabled = enable
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testing.Init()
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
// IsTestRun will return whether or not we're operating within the context of a
|
||||
// test.
|
||||
func IsTestRun() bool {
|
||||
// TODO jimlambrt 4/23 -> convert to go 1.21 built-in func when it's
|
||||
// available in boundary:
|
||||
// https://github.com/golang/go/commit/7f38067acb738c43d870400dd648662d31456f5f#diff-b3e6126779b5ec9d3d6cea7cc54054ba78f4d7a0a6248d9e458bbd9b3d72fce3
|
||||
|
||||
// just check if the test verbose (test.v) has been initialized... we don't
|
||||
// care about it's value.
|
||||
return flag.Lookup("test.v") != nil
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_IsTestRun(t *testing.T) {
|
||||
require.True(t, IsTestRun())
|
||||
}
|
||||
Loading…
Reference in new issue