Merge pull request #856 from liquidata-inc/db/dotnet-integration

/mysql-client-tests/dotnet: Iterating on dotnet mysql client test
This commit is contained in:
Dustin Brown
2020-09-04 16:03:33 -07:00
committed by GitHub
6 changed files with 261 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ RUN apt install -y \
python3.8 \
python3-pip \
curl \
wget \
pkg-config \
mysql-client \
libmysqlclient-dev \
@@ -26,6 +27,14 @@ RUN apt install -y \
ca-certificates-java \
bats
# install dotnet
RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update; \
apt-get install -y apt-transport-https && \
apt-get update && \
apt-get install -y dotnet-sdk-3.1
# install node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt install -y nodejs

136
mysql-client-tests/dotnet/.gitignore vendored Normal file
View File

@@ -0,0 +1,136 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
.vs
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.svclog
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
*.azurePubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
packages/
## TODO: If the tool you use requires repositories.config, also uncomment the next line
!packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
![Ss]tyle[Cc]op.targets
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
# =========================
# Windows detritus
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
_NCrunch*
ZZ

View File

@@ -0,0 +1,81 @@
using System;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
class TestException : Exception
{
public TestException(string message)
{
Console.WriteLine(message);
}
}
public class DoltSQL
{
public static int Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("Must supply $USER $PORT $REPO arguments.");
return 1;
}
var user = args[0];
var port = args[1];
var db = args[2];
string connStr = $"server=127.0.0.1;user={user};database={db};port={port};CharSet=utf8;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
conn.Open();
SetupTest(conn);
QueryTest(conn);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
conn.Close();
return 0;
}
public static void SetupTest(MySqlConnection conn)
{
using var cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = @"CREATE TABLE test (pk int, value int, primary key(pk))";
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO test(pk, value) VALUES(0,0)";
cmd.ExecuteNonQuery();
}
public static void QueryTest(MySqlConnection conn)
{
string sql = "SELECT count(*) as count FROM test";
using (var cmd = new MySqlCommand(sql, conn))
try
{
object result = cmd.ExecuteScalar();
if (result != null)
{
int r = Convert.ToInt32(result);
if (r != 1)
{
TestException ex = new TestException($"Expected 1, Recieved {r}");
throw ex;
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.21" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet", "dotnet.csproj", "{E77B5EEB-5826-4C3A-BABC-337ACB3E2C47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E77B5EEB-5826-4C3A-BABC-337ACB3E2C47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E77B5EEB-5826-4C3A-BABC-337ACB3E2C47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E77B5EEB-5826-4C3A-BABC-337ACB3E2C47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E77B5EEB-5826-4C3A-BABC-337ACB3E2C47}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -48,3 +48,9 @@ teardown() {
(cd $BATS_TEST_DIRNAME/c; make clean; make)
$BATS_TEST_DIRNAME/c/mysql-connector-c-test $USER $PORT $REPO_NAME
}
@test "dotnet mysql connector" {
cd $BATS_TEST_DIRNAME/dotnet/
# dotnet run uses output channel 3 which conflicts with bats so we pipe it to null
dotnet run -- $USER $PORT $REPO_NAME 3>&-
}