-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctional.go
More file actions
67 lines (53 loc) · 1.77 KB
/
Copy pathfunctional.go
File metadata and controls
67 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package proxy
//Copyright 2016 MediaMath <http://www.mediamath.com>. All rights reserved.
//Use of this source code is governed by a BSD-style
//license that can be found in the LICENSE file.
import (
"fmt"
"os"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
const (
//TestURLEnvVar is the url to run functional tests against
TestURLEnvVar = "KAFKA_PROXY_TEST_URL"
//TestTopicEnvVar is the topic to run functional tests against
TestTopicEnvVar = "KAFKA_PROXY_TEST_TOPIC"
//TestRequiredEnvVar if set to true will make tests fail
TestRequiredEnvVar = "KAFKA_PROXY_TEST_REQUIRED"
)
//IsFunctionalTestRequired returns whether SR_TEST_REQUIRED is set
func IsFunctionalTestRequired() bool {
return strings.TrimSpace(os.Getenv(TestRequiredEnvVar)) == "true"
}
//HandleFunctionalTestError will skip or fail based on whether SR_TEST_REQUIRED is set
func HandleFunctionalTestError(t testing.TB, err error) {
if err != nil && IsFunctionalTestRequired() {
require.FailNow(t, err.Error())
} else if err != nil {
t.Skip(err)
}
}
//GetFunctionalTestURL skips, fails, or returns the config variable passed in
func GetFunctionalTestURL(t *testing.T) string {
if testing.Short() {
t.Skipf("Skipping %v tests in short mode", TestURLEnvVar)
}
value := strings.TrimSpace(os.Getenv(TestURLEnvVar))
if value == "" {
HandleFunctionalTestError(t, fmt.Errorf("%v is undefined", TestURLEnvVar))
}
return value
}
//GetFunctionalTestTopic returns the configured test topic
func GetFunctionalTestTopic(t *testing.T) string {
if testing.Short() {
t.Skipf("Skipping %v tests in short mode", TestTopicEnvVar)
}
value := strings.TrimSpace(os.Getenv(TestTopicEnvVar))
if value == "" {
HandleFunctionalTestError(t, fmt.Errorf("%v is undefined", TestTopicEnvVar))
}
return value
}