-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctional.go
More file actions
79 lines (65 loc) · 2.01 KB
/
functional.go
File metadata and controls
79 lines (65 loc) · 2.01 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
68
69
70
71
72
73
74
75
76
77
78
79
package sr
//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"
"time"
"github.com/stretchr/testify/require"
)
const (
//TestURLEnvVar is the url to run functional tests against
TestURLEnvVar = "SR_TEST_SCHEMA_REGISTRY"
//TestRequiredEnvVar if set to true will make tests fail
TestRequiredEnvVar = "SR_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)
}
}
//UniqueSchema returns a schema with a unique name
func UniqueSchema() Schema {
return TestSchema(time.Now().UnixNano())
}
//UniqueSubject returns a subject with a unique name
func UniqueSubject() Subject {
unique := time.Now().Unix()
return Subject(fmt.Sprintf("ut-%v", unique))
}
//TestSchema returns a schema with the unique part added to the name
func TestSchema(unique int64) Schema {
return Schema(fmt.Sprintf(
`{
"namespace": "com.mediamath.sr",
"type": "record",
"name": "unit_test_functional_%v",
"doc": "unit test schema with unique name",
"fields": [
{ "name": "foo", "type": "long", "doc": "a long for testing" },
{ "name": "bar", "type": "string", "doc": "a string for testing"}
]
}
`, unique))
}
//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
}