-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from ankhers/specification_tests
Specification Tests
- Loading branch information
Showing
18 changed files
with
856 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Mongo.SpecificationTests.CRUDTest do | ||
use Mongo.SpecificationCase | ||
import Mongo.Specification.CRUD.Helpers | ||
require Mongo.Specification.CRUD | ||
|
||
def min_server_version?(nil), do: true | ||
def min_server_version?(number) do | ||
min_server_version = | ||
number <> ".0" | ||
|> String.split(".") | ||
|> Enum.map(&elem(Integer.parse(&1), 0)) | ||
|> List.to_tuple() | ||
|
||
mongo_version() >= min_server_version | ||
end | ||
|
||
setup_all do | ||
{:ok, pid} = Mongo.start_link(database: "mongodb_test") | ||
|
||
%{mongo: pid} | ||
end | ||
|
||
Enum.map(@crud_tests, fn file -> | ||
json = file |> File.read!() |> Jason.decode!() | ||
[file_no_suffix, _suffix] = | ||
file | ||
|> String.split("/") | ||
|> List.last() | ||
|> String.split(".") | ||
|
||
describe file do | ||
setup %{mongo: mongo} do | ||
collection = unquote(Macro.escape(file_no_suffix)) | ||
Mongo.delete_many!(mongo, collection, %{}) | ||
%{collection: collection} | ||
end | ||
|
||
Mongo.Specification.CRUD.create_tests(json) | ||
end | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"_id": 1, | ||
"x": "ping" | ||
} | ||
], | ||
"minServerVersion": "3.4", | ||
"tests": [ | ||
{ | ||
"description": "Aggregate with collation", | ||
"operation": { | ||
"name": "aggregate", | ||
"arguments": { | ||
"pipeline": [ | ||
{ | ||
"$match": { | ||
"x": "PING" | ||
} | ||
} | ||
], | ||
"collation": { | ||
"locale": "en_US", | ||
"strength": 2 | ||
} | ||
} | ||
}, | ||
"outcome": { | ||
"result": [ | ||
{ | ||
"_id": 1, | ||
"x": "ping" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"_id": 1, | ||
"x": 11 | ||
}, | ||
{ | ||
"_id": 2, | ||
"x": 22 | ||
}, | ||
{ | ||
"_id": 3, | ||
"x": 33 | ||
} | ||
], | ||
"minServerVersion": "2.6", | ||
"tests": [ | ||
{ | ||
"description": "Aggregate with $out", | ||
"operation": { | ||
"name": "aggregate", | ||
"arguments": { | ||
"pipeline": [ | ||
{ | ||
"$sort": { | ||
"x": 1 | ||
} | ||
}, | ||
{ | ||
"$match": { | ||
"_id": { | ||
"$gt": 1 | ||
} | ||
} | ||
}, | ||
{ | ||
"$out": "other_test_collection" | ||
} | ||
], | ||
"batchSize": 2 | ||
} | ||
}, | ||
"outcome": { | ||
"result": [ | ||
{ | ||
"_id": 2, | ||
"x": 22 | ||
}, | ||
{ | ||
"_id": 3, | ||
"x": 33 | ||
} | ||
], | ||
"collection": { | ||
"name": "other_test_collection", | ||
"data": [ | ||
{ | ||
"_id": 2, | ||
"x": 22 | ||
}, | ||
{ | ||
"_id": 3, | ||
"x": 33 | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"description": "Aggregate with $out and batch size of 0", | ||
"operation": { | ||
"name": "aggregate", | ||
"arguments": { | ||
"pipeline": [ | ||
{ | ||
"$sort": { | ||
"x": 1 | ||
} | ||
}, | ||
{ | ||
"$match": { | ||
"_id": { | ||
"$gt": 1 | ||
} | ||
} | ||
}, | ||
{ | ||
"$out": "other_test_collection" | ||
} | ||
], | ||
"batchSize": 0 | ||
} | ||
}, | ||
"outcome": { | ||
"result": [ | ||
{ | ||
"_id": 2, | ||
"x": 22 | ||
}, | ||
{ | ||
"_id": 3, | ||
"x": 33 | ||
} | ||
], | ||
"collection": { | ||
"name": "other_test_collection", | ||
"data": [ | ||
{ | ||
"_id": 2, | ||
"x": 22 | ||
}, | ||
{ | ||
"_id": 3, | ||
"x": 33 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.