Skip to content

Commit

Permalink
Flags to configure eventing upgrade tests forwarder (ksvc)
Browse files Browse the repository at this point in the history
This change is required to complete knative/operator#252

It enables configuring of wathola forwarder implemented as Knative
Service. Configuration is done by using new optional environment
variables.
  • Loading branch information
cardil committed Aug 20, 2020
1 parent 142fde8 commit 2c2ec1e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
16 changes: 16 additions & 0 deletions test/upgrade/prober/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"runtime"
"strings"
"text/template"

"github.com/wavesoftware/go-ensure"
Expand Down Expand Up @@ -118,3 +120,17 @@ func (p *prober) compileTemplate(templateName string, brokerUrl *apis.URL) strin
ensure.NoError(tmpl.Execute(&buff, data))
return buff.String()
}

func envflag(name string, defaultValue bool) bool {
if value, ok := os.LookupEnv(name); ok {
valid := []string{"true", "yes", "enable"}
value = strings.ToLower(value)
for _, candidate := range valid {
if value == candidate {
return true
}
}
return false
}
return defaultValue
}
55 changes: 55 additions & 0 deletions test/upgrade/prober/configuration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2020 The Knative Authors
* 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.
*/

package prober

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestEnvflag(t *testing.T) {
envname := "TestEnvflag"
suite := []struct {
env string
envSet bool
defaultValue bool
out bool
}{
{"", false, true, true},
{"", true, true, false},
{"yes", true, false, true},
{"y", true, false, false},
{"y", true, true, false},
{"true", true, false, true},
{"true", true, true, true},
{"enable", true, false, true},
{"enabled", true, false, false},
}
for _, s := range suite {
t.Run(fmt.Sprintf("env(%t)=%q,def=%t", s.envSet, s.env, s.defaultValue), func(t *testing.T) {
if s.envSet {
assert.NoError(t, os.Setenv(envname, s.env))
defer func() { assert.NoError(t, os.Unsetenv(envname)) }()
}
result := envflag(envname, s.defaultValue)

assert.Equal(t, s.out, result)
})
}
}
11 changes: 8 additions & 3 deletions test/upgrade/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import (
"knative.dev/eventing/test/lib/resources"
)

const (
ServingUseFlag = "E2E_UPGRADE_TESTS_SERVING_USE"
ServingScaleToZeroFlag = "E2E_UPGRADE_TESTS_SERVING_SCALE_TO_ZERO"
)

var (
// FIXME: Interval is set to 200 msec, as lower values will result in errors: knative/eventing#2357
// Interval = 10 * time.Millisecond
Expand Down Expand Up @@ -69,8 +74,8 @@ func NewConfig(namespace string) *Config {
FinishedSleep: 5 * time.Second,
FailOnErrors: true,
Serving: ServingConfig{
Use: false,
ScaleToZero: true,
Use: envflag(ServingUseFlag, false),
ScaleToZero: envflag(ServingScaleToZeroFlag, true),
},
}
}
Expand Down Expand Up @@ -151,7 +156,7 @@ func (p *prober) remove() {
if p.config.Serving.Use {
p.removeForwarder()
}
p.client.Tracker.Clean(true)
ensure.NoError(p.client.Tracker.Clean(true))
}

func newProber(log *zap.SugaredLogger, client *testlib.Client, config *Config) Prober {
Expand Down

0 comments on commit 2c2ec1e

Please sign in to comment.