-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_test.go
69 lines (59 loc) · 1.75 KB
/
common_test.go
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
package gorums
import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"
"testing"
)
const (
gorumsBaseImport = "github.com/relab/gorums"
devImport = gorumsBaseImport + "/" + devFolder
testdataDevImport = gorumsBaseImport + "/" + testdataFolder + "/" + devFolder
devFolder = "dev"
testdataFolder = "testdata"
regGoldenFolder = "register_golden"
regProtoFile = "register.proto"
regPbGoFile = "register.pb.go"
devRegProtoRelPath = devFolder + "/" + regProtoFile
tdRegProtoRelPath = testdataFolder + "/" + regGoldenFolder + "/" + regProtoFile
tdRegPbGoRelPath = testdataFolder + "/" + regGoldenFolder + "/" + regPbGoFile
protoc = "protoc"
protocIFlag = "-I=../../../:."
protocOutFlag = "--gorums_out=plugins=grpc+gorums:"
)
func run(t *testing.T, name string, args ...string) {
cmd := exec.Command(name, args...)
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
t.Fatal(err)
}
}
func runAndCaptureOutput(command string, args ...string) ([]byte, error) {
cmd := exec.Command(command, args...)
out, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("%v\n%s", err, out)
}
return bytes.TrimSuffix(out, []byte{'\n'}), nil
}
const (
protocVersionPrefix = "libprotoc "
currentProtocVersion = "3.2.0"
)
func checkProtocVersion(t *testing.T) {
out, err := runAndCaptureOutput("protoc", "--version")
if err != nil {
t.Skipf("skipping test due to protoc error: %v", err)
}
gotVersion := string(out)
gotVersion = strings.TrimPrefix(gotVersion, protocVersionPrefix)
if gotVersion != currentProtocVersion {
t.Skipf("skipping test due to old protoc version, got %q, required is %q", gotVersion, currentProtocVersion)
}
}