-
Notifications
You must be signed in to change notification settings - Fork 61
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
Implemented Test containers for integration testing - phase 1 #3472
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe recent updates to the Ginger project involve enhancing database integration testing capabilities and updating dependencies. The Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 13
Configuration used: CodeRabbit UI
Files selected for processing (6)
- Ginger/GingerCoreNET/GingerCoreNET.csproj (1 hunks)
- Ginger/GingerCoreNETUnitTest/DatabaseTest/CouchbaseIntegrationTests.cs (1 hunks)
- Ginger/GingerCoreNETUnitTest/DatabaseTest/OracleIntegrationTests.cs (1 hunks)
- Ginger/GingerCoreNETUnitTest/DatabaseTest/PostgreSqlIntegrationTests.cs (1 hunks)
- Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj (2 hunks)
- Ginger/GingerCoreNETUnitTest/RunTestslib/UnitTestRepositoryItemFactory.cs (2 hunks)
Files skipped from review due to trivial changes (1)
- Ginger/GingerCoreNET/GingerCoreNET.csproj
Additional comments: 3
Ginger/GingerCoreNETUnitTest/RunTestslib/UnitTestRepositoryItemFactory.cs (2)
- 12-12: The import of
Oracle.ManagedDataAccess.Client
is correctly added to support Oracle database connectivity. This change aligns with the PR's objective to enhance database integration testing.- 164-164: The modification to the
GetOracleConnection
method to return a newOracleConnection
instead of throwing aNotImplementedException
is a necessary change for enabling Oracle database tests. This aligns with the PR's objectives and improves the testing framework's capabilities.Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj (1)
- 97-100: The addition of package references for
Testcontainers
,Testcontainers.Couchbase
,Testcontainers.Oracle
, andTestcontainers.PostgreSql
with version3.7.0
is correctly implemented and aligns with the PR's objective to enhance database integration testing capabilities. Ensure that the specified version3.7.0
is compatible with the project's other dependencies to avoid any potential conflicts.
private static readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder() | ||
.WithImage("postgres:15-alpine") | ||
.Build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of a hard-coded PostgreSQL image version (postgres:15-alpine
) may lead to future compatibility issues or unexpected behavior if the image is updated or deprecated. Consider parameterizing the PostgreSQL version or using a more stable version tag.
- .WithImage("postgres:15-alpine")
+ .WithImage("postgres:latest")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
private static readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder() | |
.WithImage("postgres:15-alpine") | |
.Build(); | |
private static readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder() | |
.WithImage("postgres:latest") | |
.Build(); |
[TestCleanup] | ||
public Task DisposeAsync() | ||
{ | ||
return _postgres.DisposeAsync().AsTask(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DisposeAsync
method is marked with the [TestCleanup]
attribute but is not asynchronous. To align with best practices and the method's intent, consider marking this method as async
and using the await
keyword for the disposal operation.
- public Task DisposeAsync()
+ public async Task DisposeAsync()
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
[TestCleanup] | |
public Task DisposeAsync() | |
{ | |
return _postgres.DisposeAsync().AsTask(); | |
[TestCleanup] | |
public async Task DisposeAsync() | |
{ | |
return _postgres.DisposeAsync().AsTask(); |
command.CommandText = "CREATE TABLE Customer (Id serial PRIMARY KEY, Name varchar(255));" + | ||
"INSERT INTO Customer (Name) VALUES ('1'), ('Mahesh kale');" + | ||
"INSERT INTO Customer (Name) VALUES ('1'), ('Jinendra Ghodke');"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SQL command text concatenates strings to form a SQL query, which can be prone to SQL injection if dynamic data were ever to be included. Although this is a test environment setup, adopting best practices such as using parameterized queries is recommended to ensure security practices are followed consistently.
- command.CommandText = "CREATE TABLE Customer (Id serial PRIMARY KEY, Name varchar(255));" +
- "INSERT INTO Customer (Name) VALUES ('1'), ('Mahesh kale');" +
- "INSERT INTO Customer (Name) VALUES ('1'), ('Jinendra Ghodke');";
+ command.CommandText = @"CREATE TABLE Customer (Id serial PRIMARY KEY, Name varchar(255));
+ INSERT INTO Customer (Name) VALUES (@Name1), (@Name2);
+ INSERT INTO Customer (Name) VALUES (@Name3), (@Name4);";
+ command.Parameters.AddWithValue("@Name1", "1");
+ command.Parameters.AddWithValue("@Name2", "Mahesh kale");
+ command.Parameters.AddWithValue("@Name3", "1");
+ command.Parameters.AddWithValue("@Name4", "Jinendra Ghodke");
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
command.CommandText = "CREATE TABLE Customer (Id serial PRIMARY KEY, Name varchar(255));" + | |
"INSERT INTO Customer (Name) VALUES ('1'), ('Mahesh kale');" + | |
"INSERT INTO Customer (Name) VALUES ('1'), ('Jinendra Ghodke');"; | |
command.CommandText = @"CREATE TABLE Customer (Id serial PRIMARY KEY, Name varchar(255)); | |
INSERT INTO Customer (Name) VALUES (@Name1), (@Name2); | |
INSERT INTO Customer (Name) VALUES (@Name3), (@Name4);"; | |
command.Parameters.AddWithValue("@Name1", "1"); | |
command.Parameters.AddWithValue("@Name2", "Mahesh kale"); | |
command.Parameters.AddWithValue("@Name3", "1"); | |
command.Parameters.AddWithValue("@Name4", "Jinendra Ghodke"); |
//Assert.IsNotNull(recs.Count, 0); | ||
Assert.AreEqual(recs.Count,2, "Fetched 2 records from Postgre Table"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment //Assert.IsNotNull(recs.Count, 0);
is commented out and seems to be incorrect as Assert.IsNotNull
does not take a second argument for comparison. If the intent was to ensure recs
is not null and has a count of 0, use Assert.IsNotNull(recs)
and Assert.AreEqual(0, recs.Count)
separately.
[TestClass] | ||
public class OracleIntegrationTests | ||
{ | ||
private static readonly OracleContainer _oracleContainer = new OracleBuilder().Build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Oracle container is instantiated without specifying an image version, which could lead to unpredictable test environments due to differences in Oracle versions. Specifying a version can help ensure consistent test results.
- private static readonly OracleContainer _oracleContainer = new OracleBuilder().Build();
+ private static readonly OracleContainer _oracleContainer = new OracleBuilder().WithImage("oracle/database:19.3.0-ee").Build();
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
private static readonly OracleContainer _oracleContainer = new OracleBuilder().Build(); | |
private static readonly OracleContainer _oracleContainer = new OracleBuilder().WithImage("oracle/database:19.3.0-ee").Build(); |
public sealed class CouchbaseIntegrationTests | ||
{ | ||
|
||
private static readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder().Build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instantiating the Couchbase container without specifying an image version could lead to inconsistent test environments. It's recommended to specify a version for predictability.
- private static readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder().Build();
+ private static readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder().WithImage("couchbase/server:enterprise-6.5.1").Build();
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
private static readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder().Build(); | |
private static readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder().WithImage("couchbase/server:enterprise-6.5.1").Build(); |
[TestCleanup] | ||
public Task DisposeAsync() | ||
{ | ||
return _couchbaseContainer.DisposeAsync().AsTask(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DisposeAsync
method should be marked as async
and use the await
keyword for disposal, similar to the other test classes.
- public Task DisposeAsync()
+ public async Task DisposeAsync()
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
[TestCleanup] | |
public Task DisposeAsync() | |
{ | |
return _couchbaseContainer.DisposeAsync().AsTask(); | |
[TestCleanup] | |
public async Task DisposeAsync() | |
{ | |
return _couchbaseContainer.DisposeAsync().AsTask(); |
var cluster = new Cluster(new ClientConfiguration | ||
{ | ||
Servers = new List<Uri> { new Uri("http://" + _couchbaseContainer.GetConnectionString()) }, | ||
UseSsl = false | ||
}); | ||
|
||
cluster.Authenticate(CouchbaseBuilder.DefaultUsername, CouchbaseBuilder.DefaultPassword); | ||
|
||
var clusterManager = cluster.CreateManager(CouchbaseBuilder.DefaultUsername, CouchbaseBuilder.DefaultPassword); | ||
var buckets = clusterManager.ListBuckets().Value; | ||
//var result = clusterManager.CreateBucket(new BucketSettings() { Name = "GingerBucket", BucketType = Couchbase.Core.Buckets.BucketTypeEnum.Couchbase, AuthType = Couchbase.Authentication.AuthType.None }); | ||
//var bucket = cluster.OpenBucket("GingerBucket"); | ||
var bucket = cluster.OpenBucket(_couchbaseContainer.Buckets.FirstOrDefault().Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented-out code should be removed to keep the codebase clean and maintainable. If this code is meant for future reference, consider adding a detailed comment explaining its purpose or moving it to documentation.
- // var clusterOptions = new ClusterOptions();
- // clusterOptions.ConnectionString = _couchbaseContainer.GetConnectionString();
- // clusterOptions.UserName = CouchbaseBuilder.DefaultUsername;
- // clusterOptions.Password = CouchbaseBuilder.DefaultPassword;
- // var cluster = await Cluster.ConnectAsync(clusterOptions)
- //.ConfigureAwait(true);
- // var ping = await cluster.PingAsync()
- // .ConfigureAwait(true);
- // var bucket = await cluster.BucketAsync(_couchbaseContainer.Buckets.Single().Name)
- // .ConfigureAwait(true);
- //var database = await client.Database.PutAsync()
- // .ConfigureAwait(true);
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
var cluster = new Cluster(new ClientConfiguration | |
{ | |
Servers = new List<Uri> { new Uri("http://" + _couchbaseContainer.GetConnectionString()) }, | |
UseSsl = false | |
}); | |
cluster.Authenticate(CouchbaseBuilder.DefaultUsername, CouchbaseBuilder.DefaultPassword); | |
var clusterManager = cluster.CreateManager(CouchbaseBuilder.DefaultUsername, CouchbaseBuilder.DefaultPassword); | |
var buckets = clusterManager.ListBuckets().Value; | |
//var result = clusterManager.CreateBucket(new BucketSettings() { Name = "GingerBucket", BucketType = Couchbase.Core.Buckets.BucketTypeEnum.Couchbase, AuthType = Couchbase.Authentication.AuthType.None }); | |
//var bucket = cluster.OpenBucket("GingerBucket"); | |
var bucket = cluster.OpenBucket(_couchbaseContainer.Buckets.FirstOrDefault().Name); | |
var cluster = new Cluster(new ClientConfiguration | |
{ | |
Servers = new List<Uri> { new Uri("http://" + _couchbaseContainer.GetConnectionString()) }, | |
UseSsl = false | |
}); | |
cluster.Authenticate(CouchbaseBuilder.DefaultUsername, CouchbaseBuilder.DefaultPassword); | |
var clusterManager = cluster.CreateManager(CouchbaseBuilder.DefaultUsername, CouchbaseBuilder.DefaultPassword); | |
var buckets = clusterManager.ListBuckets().Value; | |
var bucket = cluster.OpenBucket(_couchbaseContainer.Buckets.FirstOrDefault().Name); |
catch (Exception ex) | ||
{ | ||
|
||
throw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The catch block simply rethrows the exception without any additional handling or logging. If there's no specific error handling needed, consider removing the try-catch block to let the exception propagate naturally.
- catch (Exception ex)
- {
- throw;
- }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
catch (Exception ex) | |
{ | |
throw; |
//then | ||
Assert.AreEqual(connectionSuccessful, true, "Connected Successfully to CouchbaseDB"); | ||
//Assert.IsNotNull(recs.Count, 0); | ||
Assert.AreEqual(recs.Count, 2, "Fetched 2 records from Postgre Table"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion message states "Fetched 2 records from Postgre Table," which seems to be a copy-paste error from the PostgreSQL tests. Correct the message to reflect Couchbase testing.
- Assert.AreEqual(recs.Count, 2, "Fetched 2 records from Postgre Table");
+ Assert.AreEqual(recs.Count, 2, "Fetched 2 records from Couchbase bucket");
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Assert.AreEqual(recs.Count, 2, "Fetched 2 records from Postgre Table"); | |
Assert.AreEqual(recs.Count, 2, "Fetched 2 records from Couchbase bucket"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- Ginger/GingerCoreNET/GingerCoreNET.csproj (1 hunks)
- Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- Ginger/GingerCoreNET/GingerCoreNET.csproj
- Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- Ginger/GingerCoreNET/GingerCoreNET.csproj (1 hunks)
- Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj (2 hunks)
Files skipped from review due to trivial changes (1)
- Ginger/GingerCoreNET/GingerCoreNET.csproj
Additional comments: 1
Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj (1)
- 97-100: The addition of
Testcontainers
,Testcontainers.Couchbase
,Testcontainers.Oracle
, andTestcontainers.PostgreSql
packages with version3.7.0
is a significant enhancement for integration testing, especially for database-related tests. Ensure that the version3.7.0
is compatible with the project's .NET version (net8.0
) and other dependencies to avoid any compatibility issues. Additionally, consider verifying if there are any newer versions available that might offer improvements or critical bug fixes.
Thank you for your contribution.
Before submitting this PR, please make sure:
Summary by CodeRabbit
NPOI
package to version 2.6.2 for enhanced performance and stability.Testcontainers
for more realistic database testing environments.