diff --git a/test/upgrade/prober/configuration.go b/test/upgrade/prober/configuration.go index ba1057afd1d..0307daf8b9a 100644 --- a/test/upgrade/prober/configuration.go +++ b/test/upgrade/prober/configuration.go @@ -18,17 +18,15 @@ package prober import ( "bytes" "context" + "errors" "fmt" "io/ioutil" - "os" "path" "runtime" - "strings" "text/template" "time" "github.com/kelseyhightower/envconfig" - "github.com/wavesoftware/go-ensure" "knative.dev/eventing/test/lib/resources" "knative.dev/eventing/test/upgrade/prober/sut" duckv1 "knative.dev/pkg/apis/duck/v1" @@ -44,15 +42,19 @@ const ( defaultHealthEndpoint = "/healthz" defaultFinishedSleep = 5 * time.Second + // Silence will suppress notification about event duplicates. Silence DuplicateAction = "silence" - Warn DuplicateAction = "warn" - Error DuplicateAction = "error" + // Warn will issue a warning message in case of a event duplicate. + Warn DuplicateAction = "warn" + // Error will fail test with an error in case of event duplicate. + Error DuplicateAction = "error" prefix = "eventing_upgrade_tests" +) - // TODO(ksuszyns): Remove this val in next release - // Deprecated: use 'eventing_upgrade_tests' prefix instead - deprecatedPrefix = "e2e_upgrade_tests" +var ( + // ErrInvalidConfig is returned when the configuration is invalid. + ErrInvalidConfig = errors.New("invalid config") ) // DuplicateAction is the action to take in case of duplicated events @@ -67,15 +69,6 @@ type Config struct { FailOnErrors bool OnDuplicate DuplicateAction Ctx context.Context - // BrokerOpts holds opts for broker. - // TODO(ksuszyns): Remove this opt in next release - // Deprecated: use Wathola.SystemUnderTest instead. - BrokerOpts []resources.BrokerOption - // Namespace holds namespace in which test is about to be executed. - // TODO(ksuszyns): Remove this opt in next release - // Deprecated: namespace is about to be taken from testlib.Client created by - // NewRunner - Namespace string } // Wathola represents options related strictly to wathola testing tool. @@ -106,36 +99,15 @@ type ServingConfig struct { // NewConfigOrFail will create a prober.Config or fail trying. func NewConfigOrFail(c pkgupgrade.Context) *Config { - errSink := func(err error) { + cfg, err := NewConfig() + if err != nil { c.T.Fatal(err) } - warnf := c.Log.Warnf - return newConfig(errSink, warnf) -} - -// NewConfig creates a new configuration object with default values filled in. -// Values can be influenced by kelseyhightower/envconfig with -// `eventing_upgrade_tests` prefix. -// TODO(ksuszyns): Remove this func in next release -// Deprecated: use NewContinualVerification or NewConfigOrFail -func NewConfig(namespace ...string) *Config { - errSink := func(err error) { - ensure.NoError(err) - } - warnf := func(template string, args ...interface{}) { - _, err := fmt.Fprintf(os.Stderr, template, args) - ensure.NoError(err) - } - config := newConfig(errSink, warnf) - if len(namespace) > 0 { - config.Namespace = strings.Join(namespace, ",") - } - return config + return cfg } -func newConfig( - errSink func(err error), warnf func(template string, args ...interface{}), -) *Config { +// NewConfig will create a prober.Config or return error. +func NewConfig() (*Config, error) { config := &Config{ Interval: Interval, FinishedSleep: defaultFinishedSleep, @@ -160,22 +132,10 @@ func newConfig( } if err := envconfig.Process(prefix, config); err != nil { - errSink(err) + return nil, fmt.Errorf("%w: %v", ErrInvalidConfig, err) } - // TODO(ksuszyns): Remove this block in next release - for _, enventry := range os.Environ() { - if strings.HasPrefix(strings.ToLower(enventry), deprecatedPrefix) { - warnf( - "DEPRECATED: using deprecated '%s' prefix. Use '%s' instead.", - deprecatedPrefix, prefix) - if err := envconfig.Process(deprecatedPrefix, config); err != nil { - errSink(err) - } - break - } - } - return config + return config, nil } func (p *prober) deployConfiguration() { diff --git a/test/upgrade/prober/prober.go b/test/upgrade/prober/prober.go index 201dc686228..2c204eb914f 100644 --- a/test/upgrade/prober/prober.go +++ b/test/upgrade/prober/prober.go @@ -16,15 +16,11 @@ package prober import ( - "context" - "reflect" - "testing" "time" "go.uber.org/zap" testlib "knative.dev/eventing/test/lib" "knative.dev/eventing/test/lib/resources" - "knative.dev/eventing/test/upgrade/prober/sut" pkgupgrade "knative.dev/pkg/test/upgrade" ) @@ -33,21 +29,6 @@ var ( Interval = 10 * time.Millisecond ) -// Prober is the interface for a prober, which checks the result of the probes -// when stopped. -// TODO(ksuszyns): Remove this interface in next release -// Deprecated: use Runner instead, create it with NewRunner func. -type Prober interface { - // Verify will verify prober state after finished has been send - Verify() ([]error, int) - - // Finish send finished event - Finish() - - // ReportErrors will reports found errors in proper way - ReportErrors(errors []error) -} - // Runner will run continual verification with provided configuration. type Runner interface { // Setup will start a continual prober in background. @@ -72,7 +53,6 @@ type probeRunner struct { } func (p *probeRunner) Setup(ctx pkgupgrade.Context) { - p.validate(ctx) p.log = ctx.Log p.client = testlib.Setup(ctx.T, false, p.options...) p.deploy() @@ -102,61 +82,6 @@ func (p *probeRunner) Verify(ctx pkgupgrade.Context) { p.ReportErrors(errors) } -func (p *probeRunner) validate(ctx pkgupgrade.Context) { - if p.config.Namespace != "" { - ctx.Log.Warnf( - "DEPRECATED: namespace set in Config: %s. Ignoring it.", - p.client.Namespace) - } - if len(p.config.BrokerOpts) > 0 { - ctx.Log.Warn( - "DEPRECATED: BrokerOpts set in Config. Use custom SystemUnderTest") - if reflect.ValueOf(p.config.Wathola.SystemUnderTest) == reflect.ValueOf(sut.NewDefault) { - bt := sut.NewDefault().(*sut.BrokerAndTriggers) - bt.Opts = append(bt.Opts, p.config.BrokerOpts...) - p.config.Wathola.SystemUnderTest = bt - } else { - ctx.T.Fatal("Can't use given BrokerOpts, as custom SUT is used as " + - "well. Drop using BrokerOpts in favor of custom SUT.") - } - } -} - -// RunEventProber starts a single Prober of the given domain. -// TODO(ksuszyns): Remove this func in next release -// Deprecated: use NewRunner func instead. -func RunEventProber(ctx context.Context, log *zap.SugaredLogger, client *testlib.Client, config *Config) Prober { - log.Warn("prober.RunEventProber is deprecated. Use NewRunner instead.") - config.Ctx = ctx - p := &prober{ - log: log, - client: client, - config: config, - } - p.deploy() - return p -} - -// AssertEventProber will send finish event and then verify if all events -// propagated well. -// TODO(ksuszyns): Remove this func in next release -// Deprecated: use NewRunner func instead. -func AssertEventProber(ctx context.Context, t *testing.T, probe Prober) { - t.Log("WARN: prober.AssertEventProber is deprecated. " + - "Use NewRunner instead.") - p := probe.(*prober) - p.client.T = t - p.config.Ctx = ctx - pr := &probeRunner{ - prober: p, - options: nil, - } - pr.Verify(pkgupgrade.Context{ - T: t, - Log: p.log, - }) -} - type prober struct { log *zap.SugaredLogger client *testlib.Client diff --git a/test/upgrade/prober/prober_test.go b/test/upgrade/prober/prober_test.go index db658cf1902..5f6cdca3062 100644 --- a/test/upgrade/prober/prober_test.go +++ b/test/upgrade/prober/prober_test.go @@ -16,6 +16,7 @@ package prober_test import ( + "errors" "fmt" "os" "testing" @@ -46,15 +47,13 @@ func TestNewConfig(t *testing.T) { } }() - if s.panics { - assert.Panics(t, func() { - prober.NewConfig() - }) + config, err := prober.NewConfig() + if !errors.Is(err, s.err) { + t.Fatalf("want err: %v, got err: %v", s.err, err) + } + if err != nil { return } - - config := prober.NewConfig() - assert.Equal(t, s.servingUse, config.Serving.Use) assert.True(t, config.Serving.ScaleToZero) assert.Equal(t, s.configFilename, config.ConfigFilename) @@ -63,10 +62,10 @@ func TestNewConfig(t *testing.T) { } type testCase struct { - env map[string]string - panics bool servingUse bool configFilename string + env map[string]string + err error } func createTestSuite() []testCase { @@ -83,7 +82,7 @@ func createTestSuite() []testCase { c.env = map[string]string{ servingEnvName: "gibberish", } - c.panics = true + c.err = prober.ErrInvalidConfig }), createTestCase(func(c *testCase) { c.env = map[string]string{ @@ -96,10 +95,9 @@ func createTestSuite() []testCase { func createTestCase(overrides func(*testCase)) testCase { c := testCase{ - map[string]string{}, - false, - false, - defaultConfigFilename, + servingUse: false, + configFilename: defaultConfigFilename, + env: map[string]string{}, } overrides(&c) return c