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

Implemented Test containers for integration testing - phase 1 #3472

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Maheshkale447
Copy link
Contributor

@Maheshkale447 Maheshkale447 commented Jan 29, 2024

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • Chores
    • Updated the NPOI package to version 2.6.2 for enhanced performance and stability.
  • New Features
    • Introduced functionality for testing the integration of the application with Couchbase, Oracle, and PostgreSQL databases.
  • Tests
    • Added comprehensive integration tests for Couchbase, Oracle, and PostgreSQL databases to validate data retrieval and database connectivity.
    • Enhanced testing infrastructure with the addition of Testcontainers for more realistic database testing environments.

Copy link
Contributor

coderabbitai bot commented Jan 29, 2024

Walkthrough

The recent updates to the Ginger project involve enhancing database integration testing capabilities and updating dependencies. The NPOI package version was upgraded in the core project, while the unit test project saw the addition of new package references for database containers, enabling integration tests with Couchbase, Oracle, and PostgreSQL databases. Additionally, there's an improvement in Oracle database connectivity within the unit test utility classes.

Changes

Files Change Summary
GingerCoreNET.csproj Updated NPOI package from 2.5.3 to 2.6.2
GingerCoreNETUnitTest.csproj Added package references for Testcontainers, Testcontainers.Couchbase, Testcontainers.Oracle, Testcontainers.PostgreSql
CouchbaseIntegrationTests.cs, OracleIntegrationTests.cs, PostgreSqlIntegrationTests.cs Added integration tests for Couchbase, Oracle, and PostgreSQL database functionality
UnitTestRepositoryItemFactory.cs Enhanced Oracle database connectivity by implementing GetOracleConnection method

🐇✨

In the world of code where changes abound,

A rabbit hopped in, updates it found.

With a leap and a thump, on databases it tested,

Ensuring connections, in containers nested. 🌟

🐇✨

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between ebf3810 and 4284211.
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 new OracleConnection instead of throwing a NotImplementedException 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, and Testcontainers.PostgreSql with version 3.7.0 is correctly implemented and aligns with the PR's objective to enhance database integration testing capabilities. Ensure that the specified version 3.7.0 is compatible with the project's other dependencies to avoid any potential conflicts.

Comment on lines +14 to +16
private static readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder()
.WithImage("postgres:15-alpine")
.Build();
Copy link
Contributor

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.

Suggested change
private static readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder()
.WithImage("postgres:15-alpine")
.Build();
private static readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder()
.WithImage("postgres:latest")
.Build();

Comment on lines +26 to +29
[TestCleanup]
public Task DisposeAsync()
{
return _postgres.DisposeAsync().AsTask();
Copy link
Contributor

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.

Suggested change
[TestCleanup]
public Task DisposeAsync()
{
return _postgres.DisposeAsync().AsTask();
[TestCleanup]
public async Task DisposeAsync()
{
return _postgres.DisposeAsync().AsTask();

Comment on lines +40 to +42
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');";
Copy link
Contributor

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.

Suggested change
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");

Comment on lines +76 to +77
//Assert.IsNotNull(recs.Count, 0);
Assert.AreEqual(recs.Count,2, "Fetched 2 records from Postgre Table");
Copy link
Contributor

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();
Copy link
Contributor

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.

Suggested change
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();
Copy link
Contributor

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.

Suggested change
private static readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder().Build();
private static readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder().WithImage("couchbase/server:enterprise-6.5.1").Build();

Comment on lines +28 to +31
[TestCleanup]
public Task DisposeAsync()
{
return _couchbaseContainer.DisposeAsync().AsTask();
Copy link
Contributor

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.

Suggested change
[TestCleanup]
public Task DisposeAsync()
{
return _couchbaseContainer.DisposeAsync().AsTask();
[TestCleanup]
public async Task DisposeAsync()
{
return _couchbaseContainer.DisposeAsync().AsTask();

Comment on lines +56 to +68
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);
Copy link
Contributor

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.

Suggested change
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);

Comment on lines +80 to +83
catch (Exception ex)
{

throw;
Copy link
Contributor

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.

Suggested change
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");
Copy link
Contributor

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.

Suggested change
Assert.AreEqual(recs.Count, 2, "Fetched 2 records from Postgre Table");
Assert.AreEqual(recs.Count, 2, "Fetched 2 records from Couchbase bucket");

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 4284211 and 7d8ba79.
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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 7d8ba79 and dd477e2.
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, and Testcontainers.PostgreSql packages with version 3.7.0 is a significant enhancement for integration testing, especially for database-related tests. Ensure that the version 3.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant