-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_test.go
More file actions
78 lines (65 loc) · 1.63 KB
/
version_test.go
File metadata and controls
78 lines (65 loc) · 1.63 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
// Copyright The ActForGood Authors.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://github.com/actforgood/xver/blob/main/LICENSE
package xver_test
import (
"reflect"
"runtime/debug"
"testing"
"testing/synctest"
"github.com/actforgood/xver"
)
func TestInformation(t *testing.T) {
t.Parallel()
// arrange
expected := xver.Info{}
expected.App.Name = "xver.test"
if goBuildInfo, available := debug.ReadBuildInfo(); available {
expected.Build.Go = goBuildInfo.GoVersion[2:] // without the "go" prefix
expected.App.Version = goBuildInfo.Main.Version
for _, setting := range goBuildInfo.Settings {
switch setting.Key {
case "GOOS":
expected.Build.OS = setting.Value
if expected.Build.OS == "windows" {
expected.App.Name += ".exe"
}
case "GOARCH":
expected.Build.Arch = setting.Value
}
}
}
subject := xver.Information
// act
actual := subject()
// assert
if !reflect.DeepEqual(expected, actual) {
t.Errorf(
"\n\texpected \"%+v\" (%T),\n\tbut got \"%+v\" (%T)\n",
expected, expected,
actual, actual,
)
}
}
func TestInformation_concurrency(t *testing.T) {
t.Parallel()
// Note: this test does not expect much of a thing; it is meant to
// see if something goes wrong in `test -race ...` context.
synctest.Test(t, func(t *testing.T) {
// arrange
const goroutinesNo = 50
subject := xver.Information
// act
for range goroutinesNo {
go func() {
actual := subject()
// assert
if len(actual.Build.Go) == 0 {
t.Errorf("expected go version to be set")
}
}()
}
synctest.Wait()
})
}