Skip to content

Commit 31ef273

Browse files
GODRIVER-3445 Use Git submodules for spec tests (#2007)
Co-authored-by: Matt Dale <[email protected]>
1 parent 8c13bc5 commit 31ef273

26 files changed

+1158
-679
lines changed

.evergreen/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ functions:
3232
type: system
3333
params:
3434
directory: src/go.mongodb.org/mongo-driver
35+
- command: shell.exec
36+
params:
37+
working_dir: "src/go.mongodb.org/mongo-driver"
38+
script: |
39+
git submodule update --init
3540
# Make an env.sh and evergreen expansion file with dynamic values
3641
- command: subprocess.exec
3742
params:

.github/dependabot.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ updates:
1111
- package-ecosystem: gomod
1212
directory: /
1313
schedule:
14-
interval: "weekly"
14+
interval: "weekly"
15+
- package-ecosystem: "gitsubmodule"
16+
directory: "/"
17+
schedule:
18+
interval: "weekly"

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "specifications"]
2-
path = specifications
3-
url = git@github.com:mongodb/specifications.git
2+
path = testdata/specifications
3+
url = https://github.com/mongodb/specifications

Taskfile.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ tasks:
1717

1818
check-license: bash etc/check_license.sh
1919

20+
init-submodule: git submodule update --init
21+
2022
build:
2123
deps: [install-libmongocrypt]
2224
cmds:
@@ -125,7 +127,7 @@ tasks:
125127
- go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} DYLD_LIBRARY_PATH=$MACOS_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s -p 1 ./... >> test.suite
126128

127129
evg-test-atlas-data-lake:
128-
- ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./internal/integration -run TestUnifiedSpecs/atlas-data-lake-testing >> spec_test.suite
130+
- ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./internal/integration/unified -run TestUnifiedSpec/atlas-data-lake-testing >> spec_test.suite
129131
- ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./internal/integration -run TestAtlasDataLake >> spec_test.suite
130132

131133
evg-test-enterprise-auth:
@@ -151,9 +153,6 @@ tasks:
151153
evg-test-load-balancers:
152154
# Load balancer should be tested with all unified tests as well as tests in the following
153155
# components: retryable reads, retryable writes, change streams, initial DNS seedlist discovery.
154-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/retryable-reads -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
155-
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableWritesSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
156-
- go test ${BUILD_TAGS} ./internal/integration -run TestChangeStreamSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
157156
- go test ${BUILD_TAGS} ./internal/integration -run TestInitialDNSSeedlistDiscoverySpec/load_balanced -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
158157
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancerSupport -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
159158
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancedConnectionHandshake -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
@@ -169,20 +168,15 @@ tasks:
169168
evg-test-serverless:
170169
# Serverless should be tested with all unified tests as well as tests in the following components: CRUD, load balancer,
171170
# retryable reads, retryable writes, sessions, transactions and cursor behavior.
172-
- go test ${BUILD_TAGS} ./internal/integration -run TestCrudSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
173171
- go test ${BUILD_TAGS} ./internal/integration -run TestWriteErrorsWithLabels -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
174172
- go test ${BUILD_TAGS} ./internal/integration -run TestWriteErrorsDetails -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
175173
- go test ${BUILD_TAGS} ./internal/integration -run TestHintErrors -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
176174
- go test ${BUILD_TAGS} ./internal/integration -run TestWriteConcernError -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
177175
- go test ${BUILD_TAGS} ./internal/integration -run TestErrorsCodeNamePropagated -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
178176
- go test ${BUILD_TAGS} ./internal/integration -run TestLoadBalancerSupport -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
179-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/retryable-reads -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
180177
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableReadsProse -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
181-
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableWritesSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
182178
- go test ${BUILD_TAGS} ./internal/integration -run TestRetryableWritesProse -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
183-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/sessions -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
184179
- go test ${BUILD_TAGS} ./internal/integration -run TestSessionsProse -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
185-
- go test ${BUILD_TAGS} ./internal/integration -run TestUnifiedSpecs/transactions/legacy -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
186180
- go test ${BUILD_TAGS} ./internal/integration -run TestConvenientTransactions -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
187181
- go test ${BUILD_TAGS} ./internal/integration -run TestCursor -v -timeout {{.TEST_TIMEOUT}}s >> test.suite
188182
- go test ${BUILD_TAGS} ./internal/integration/unified -run TestUnifiedSpec -v -timeout {{.TEST_TIMEOUT}}s >> test.suite

bson/bson_binary_vector_spec_test.go

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import (
1515
"testing"
1616

1717
"go.mongodb.org/mongo-driver/v2/internal/require"
18+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
1819
)
1920

20-
const bsonBinaryVectorDir = "../testdata/bson-binary-vector/"
21+
var bsonBinaryVectorDir = spectest.Path("bson-binary-vector")
2122

2223
type bsonBinaryVectorTests struct {
2324
Description string `json:"description"`
@@ -128,18 +129,7 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
128129
require.NoError(t, err, "decoding canonical BSON")
129130

130131
t.Run("Unmarshaling", func(t *testing.T) {
131-
skipCases := map[string]string{
132-
"Overflow Vector INT8": "compile-time restriction",
133-
"Underflow Vector INT8": "compile-time restriction",
134-
"INT8 with float inputs": "compile-time restriction",
135-
"Overflow Vector PACKED_BIT": "compile-time restriction",
136-
"Underflow Vector PACKED_BIT": "compile-time restriction",
137-
"Vector with float values PACKED_BIT": "compile-time restriction",
138-
"Negative padding PACKED_BIT": "compile-time restriction",
139-
}
140-
if reason, ok := skipCases[test.Description]; ok {
141-
t.Skipf("skip test case %s: %s", test.Description, reason)
142-
}
132+
spectest.CheckSkip(t)
143133

144134
errMap := map[string]string{
145135
"FLOAT32 with padding": "padding must be 0",
@@ -163,24 +153,7 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
163153
})
164154

165155
t.Run("Marshaling", func(t *testing.T) {
166-
skipCases := map[string]string{
167-
"FLOAT32 with padding": "private padding field",
168-
"Insufficient vector data with 3 bytes FLOAT32": "invalid case",
169-
"Insufficient vector data with 5 bytes FLOAT32": "invalid case",
170-
"Overflow Vector INT8": "compile-time restriction",
171-
"Underflow Vector INT8": "compile-time restriction",
172-
"INT8 with padding": "private padding field",
173-
"INT8 with float inputs": "compile-time restriction",
174-
"Overflow Vector PACKED_BIT": "compile-time restriction",
175-
"Underflow Vector PACKED_BIT": "compile-time restriction",
176-
"Vector with float values PACKED_BIT": "compile-time restriction",
177-
"Padding specified with no vector data PACKED_BIT": "run in alternative case",
178-
"Exceeding maximum padding PACKED_BIT": "run in alternative case",
179-
"Negative padding PACKED_BIT": "compile-time restriction",
180-
}
181-
if reason, ok := skipCases[test.Description]; ok {
182-
t.Skipf("skip test case %s: %s", test.Description, reason)
183-
}
156+
spectest.CheckSkip(t)
184157

185158
t.Parallel()
186159

bson/bson_corpus_spec_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
"go.mongodb.org/mongo-driver/v2/internal/assert"
2525
"go.mongodb.org/mongo-driver/v2/internal/require"
26+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
2627
)
2728

2829
type testCase struct {
@@ -57,7 +58,7 @@ type parseErrorTestCase struct {
5758
String string `json:"string"`
5859
}
5960

60-
const dataDir = "../testdata/bson-corpus/"
61+
var dataDir = spectest.Path("bson-corpus/tests")
6162

6263
func findJSONFilesInDir(dir string) ([]string, error) {
6364
files := make([]string, 0)

internal/integration/client_side_encryption_spec_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ package integration
1111

1212
import (
1313
"os"
14-
"path"
14+
"path/filepath"
1515
"regexp"
1616
"testing"
17-
)
1817

19-
const (
20-
encryptionSpecName = "client-side-encryption/legacy"
18+
"go.mongodb.org/mongo-driver/v2/internal/spectest"
2119
)
2220

21+
var encryptionSpecDir = spectest.Path("client-side-encryption/tests/legacy")
22+
2323
func verifyClientSideEncryptionVarsSet(t *testing.T) {
2424
t.Helper()
2525

@@ -53,7 +53,7 @@ func verifyClientSideEncryptionVarsSet(t *testing.T) {
5353
func TestClientSideEncryptionSpec(t *testing.T) {
5454
verifyClientSideEncryptionVarsSet(t)
5555

56-
for _, fileName := range jsonFilesInDir(t, path.Join(dataPath, encryptionSpecName)) {
56+
for _, fileName := range jsonFilesInDir(t, encryptionSpecDir) {
5757
t.Run(fileName, func(t *testing.T) {
5858
re := regexp.MustCompile(`fle2\-Range\-.*\-Correctness`)
5959
if re.Match([]byte(fileName)) {
@@ -62,7 +62,7 @@ func TestClientSideEncryptionSpec(t *testing.T) {
6262
if fileName == "kmipKMS.json" && "" == os.Getenv("KMS_MOCK_SERVERS_RUNNING") {
6363
t.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")
6464
}
65-
runSpecTestFile(t, encryptionSpecName, fileName)
65+
runSpecTestFile(t, filepath.Join(encryptionSpecDir, fileName))
6666
})
6767
}
6868
}

internal/integration/cmd_monitoring_helpers_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,30 @@ func compareValues(mt *mtest.T, key string, expected, actual bson.RawValue) erro
8383
if typeVal, err := e.LookupErr("$$type"); err == nil {
8484
// $$type represents a type assertion
8585
// for example {field: {$$type: "binData"}} should assert that "field" is an element with a binary value
86-
return checkValueType(mt, key, actual.Type, typeVal.StringValue())
86+
types := []string{}
87+
switch typeVal.Type {
88+
case bson.TypeArray:
89+
elems, err := typeVal.Array().Values()
90+
if err != nil {
91+
return fmt.Errorf("error getting expected types: %v", err)
92+
}
93+
94+
for _, elem := range elems {
95+
types = append(types, elem.StringValue())
96+
}
97+
case bson.TypeString:
98+
types = append(types, typeVal.StringValue())
99+
}
100+
101+
// If at least one of the types does not return an error, then the test
102+
// has passed.
103+
for _, t := range types {
104+
if err := checkValueType(mt, key, actual.Type, t); err == nil {
105+
return nil
106+
}
107+
}
108+
109+
return fmt.Errorf("BSON type mismatch for key %s; expected one of %v, got %s", key, types, actual.Type)
87110
}
88111

89112
a := actual.Document()

0 commit comments

Comments
 (0)