Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CodeCov for Native Code #253

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.0"
distribution-version = "2201.9.0"

[[package]]
org = "ballerina"
name = "crypto"
version = "2.6.2"
version = "2.7.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -36,6 +36,26 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
Expand All @@ -45,6 +65,12 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"
scope = "testOnly"

[[package]]
org = "ballerina"
name = "lang.value"
Expand All @@ -70,7 +96,7 @@ modules = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.2.2"
version = "1.2.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -82,6 +108,7 @@ version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
Expand Down
34 changes: 20 additions & 14 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def stripBallerinaExtensionVersion(String extVersion) {
ballerina {
packageOrganization = packageOrg
module = packageName
testCoverageParam = "--code-coverage --coverage-format=xml"
testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.mongodb.*:ballerina.mongodb*"
isConnector = true
platform = "java17"
}
Expand Down Expand Up @@ -91,26 +91,32 @@ task commitTomlFiles {
}

task startMongodbServer() {
doLast {
println("Starting mongodb server...")
exec {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker-compose -f tests/resources/docker/docker-compose.yml up && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker/docker-compose.yml up -d"
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(":${packageName}-ballerina:test")) {
println("Starting mongodb server...")
exec {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker-compose -f tests/resources/docker/docker-compose.yml up && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker/docker-compose.yml up -d"
}
}
}
}
}

task stopMongodbServer() {
doLast {
println("Stopping mongodb server...")
exec {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker-compose -f tests/resources/docker/docker-compose.yml down && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker/docker-compose.yml down"
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(":${packageName}-ballerina:test")) {
println("Stopping mongodb server...")
exec {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker-compose -f tests/resources/docker/docker-compose.yml down && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker/docker-compose.yml down"
}
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions ballerina/collection.bal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
# + documents - The documents to insert
# + options - The options to apply to the operation
# + return - An error if the operation failed, otherwise nil
isolated remote function insertMany(record {|anydata...;|}[] documents, InsertManyOptions options = {}) returns Error? {
isolated remote function insertMany(record {|anydata...;|}[] documents, InsertManyOptions options = {})

Check warning on line 54 in ballerina/collection.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/collection.bal#L54

Added line #L54 was not covered by tests
returns Error? {
string[] documentString = documents.'map((doc) => doc.toJsonString());
return check insertMany(self, documentString, options);
}
Expand All @@ -67,7 +68,8 @@
# + targetType - The type of the returned documents
# + return - A stream of documents which match the provided filter, or an error if the operation failed
isolated remote function find(map<json> filter = {}, FindOptions findOptions = {}, map<json>? projection = (),
typedesc<record {|anydata...;|}> targetType = <>) returns stream<targetType, error?>|Error = @java:Method {
typedesc<record {|anydata...;|}|record {|anydata...;|}[]> targetType = <>)

Check warning on line 71 in ballerina/collection.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/collection.bal#L71

Added line #L71 was not covered by tests
returns stream<targetType, error?>|Error = @java:Method {
'class: "io.ballerina.lib.mongodb.Collection"
} external;

Expand All @@ -80,7 +82,7 @@
# + targetType - The type of the returned document
# + return - The document which matches the provided filter, or an error if the operation failed
isolated remote function findOne(map<json> filter = {}, FindOptions findOptions = {}, map<json>? projection = (),
typedesc<record {|anydata...;|}> targetType = <>) returns targetType|Error? = @java:Method {
typedesc<record {|anydata...;|}> targetType = <>) returns targetType|Error? = @java:Method {

Check warning on line 85 in ballerina/collection.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/collection.bal#L85

Added line #L85 was not covered by tests
'class: "io.ballerina.lib.mongodb.Collection"
} external;

Expand Down
52 changes: 52 additions & 0 deletions ballerina/tests/03_collection_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,58 @@ isolated function testComplexFind() returns error? {
check database->drop();
}

@test:Config {
groups: ["collection", "aggregate", "sort"]
}
isolated function testFindReturningArray() returns error? {
Database database = check mongoClient->getDatabase("testFindReturningArrayDB");
Collection tvShowsCollection = check database->getCollection("TvShows");
Collection directorsCollection = check database->getCollection("Directors");

TvShow tvShow1 = {title: "Breaking Bad", year: 2008, directorId: "1"};
TvShow tvShow2 = {title: "Game of Thrones", year: 2011, directorId: "2"};
TvShow tvShow3 = {title: "The Walking Dead", year: 2010, directorId: "3"};
TvShow tvShow4 = {title: "Better Call Saul", year: 2015, directorId: "1"};
check tvShowsCollection->insertMany([tvShow1, tvShow2, tvShow3, tvShow4]);

Director director1 = {id: "1", name: "Vince Gilligan"};
Director director2 = {id: "2", name: "David Benioff"};
Director director3 = {id: "3", name: "Frank Darabont"};
check directorsCollection->insertMany([director1, director2, director3]);

stream<record {
TvShow[] tvShows;
}, error?> result = check tvShowsCollection->aggregate([
{
\$group: {
_id: {directorId: "$directorId"},
tvShows: {
\$push: {
title: "$title",
year: "$year",
directorId: "$directorId"
}
}
}
},
{
\$sort: {
"tvShows.directorId": 1
}
}
]);
TvShow[][] actualResult = check from record {
TvShow[] tvShows;
} item in result
select item.tvShows;
TvShow[][] expectedResult = [[tvShow1, tvShow4], [tvShow2], [tvShow3]];
check result.close();
check tvShowsCollection->drop();
check directorsCollection->drop();
check database->drop();
test:assertEquals(actualResult, expectedResult);
}

@test:Config {
groups: ["collection", "insert", "aggregate", "projection"]
}
Expand Down
11 changes: 11 additions & 0 deletions ballerina/tests/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ type Author readonly & record {|
string name;
Book[] books;
|};

type TvShow record {|
string title;
int year;
string directorId;
|};

type Director record {|
string id;
string name;
|};
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ allprojects {
task build {
dependsOn(":mongodb-native:build")
dependsOn(":mongodb-ballerina:build")
dependsOn(":mongodb-examples:build")
}
task test {
dependsOn(":mongodb-ballerina:test")
dependsOn(":mongodb-examples:test")
}

def moduleVersion = project.version.replace("-SNAPSHOT", "")
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# Change Log

This file contains all the notable changes done to the Ballerina GraphQL package through the releases.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- [[#6377] Allow Returning Arrays from `find` and `aggregate` Operations](https://github.com/ballerina-platform/ballerina-standard-library/issues/6377)

## [5.0.0] - 2024-04-02

### Changed

- [[#5073] Revamping the connector with new Client, Database, and Collection model](https://github.com/ballerina-platform/ballerina-standard-library/issues/5073)
2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ task buildExamples {
if (graph.hasTask(":mongodb-examples:test")) {
buildExamples.enabled = false
} else {
testExamples.enabled = false
testExamples.enabled = true
}
}
doLast {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.caching=true
group=io.ballerina.lib
version=5.0.1-SNAPSHOT
ballerinaLangVersion=2201.8.6
ballerinaLangVersion=2201.9.0

checkstylePluginVersion=10.12.0
spotbugsPluginVersion=5.0.14
Expand Down
Loading