tiny_tds 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ # this should mirror the steps outlined in the circleci yml
7
+ echo "Installing mssql-tools..."
8
+ sleep 5
9
+ sudo -E ./test/bin/install-mssqltools.sh
10
+
11
+ echo "Configurating tinytds test database..."
12
+ sleep 5
13
+ ./test/bin/setup_tinytds_db.sh
14
+
15
+ echo "Building openssl library..."
16
+ sleep 5
17
+ sudo -E ./test/bin/install-openssl.sh
18
+
19
+ echo "Building freetds library..."
20
+ sleep 5
21
+ sudo -E ./test/bin/install-freetds.sh
22
+
23
+ echo "Installing gems..."
24
+ sleep 5
25
+ bundle install
data/start_dev.sh ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ # set volume read/write permissions to work both outside and inside container
7
+ sudo ./test/bin/setup_volume_permissions.sh
8
+
9
+ docker-compose up -d
10
+ echo "Waiting for containers to start..."
11
+ sleep 10
12
+
13
+ # setup circleci ruby container for development
14
+ docker exec cimg_ruby bash -c './setup_cimgruby_dev.sh'
15
+
16
+ # enter container
17
+ set +x
18
+ echo "cimg/ruby container is ready for tiny_tds development.........."
19
+ echo "To enter container run: docker exec -it cimg_ruby /bin/bash"
20
+ echo "To build solution run: docker exec cimg_ruby bash -c 'bundle exec rake build'"
21
+ echo "To test solution run: docker exec cimg_ruby bash -c 'bundle exec rake test'"
@@ -1,14 +1,23 @@
1
1
  # encoding: UTF-8
2
2
 
3
- desc 'Build the windows binary gems per rake-compiler-dock'
4
- task 'gem:windows' => ['ports:cross'] do
3
+ desc 'Build the native binary gems using rake-compiler-dock'
4
+ task 'gem:native' => ['ports:cross'] do
5
5
  require 'rake_compiler_dock'
6
6
 
7
7
  # make sure to install our bundle
8
- build = ['bundle']
8
+ sh "bundle package --all" # Avoid repeated downloads of gems by using gem files from the host.
9
9
 
10
- # and finally build the native gem
11
- build << 'rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0:2.4.0 CFLAGS="-Wall" MAKE="make -j`nproc`"'
10
+ GEM_PLATFORM_HOSTS.each do |plat, meta|
11
+ RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{meta[:ruby_versions]} rake native:#{plat} gem", platform: plat
12
+ end
13
+ end
14
+
15
+ # assumes you are in a container provided by Rake compiler
16
+ # if not, use the task above
17
+ task 'gem:for_platform', [:gem_platform] do |_task, args|
18
+ args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
12
19
 
13
- RakeCompilerDock.sh build.join(' && ')
20
+ sh "bundle install"
21
+ Rake::Task["ports:compile"].invoke(GEM_PLATFORM_HOSTS[args.gem_platform][:host], args.gem_platform)
22
+ sh "RUBY_CC_VERSION=#{GEM_PLATFORM_HOSTS[args.gem_platform][:ruby_versions]} rake native:#{args.gem_platform} gem"
14
23
  end
@@ -8,25 +8,8 @@ module Ports
8
8
  set_patches
9
9
  end
10
10
 
11
- def cook
12
- chdir_for_build do
13
- super
14
- end
15
- self
16
- end
17
-
18
11
  private
19
12
 
20
- # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
21
- # folders don't support symlinks, but libiconv expects it for a build on
22
- # Linux. We work around this limitation by using the temp dir for cooking.
23
- def chdir_for_build
24
- build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
25
- Dir.chdir(build_dir) do
26
- yield
27
- end
28
- end
29
-
30
13
  def configure_defaults
31
14
  [
32
15
  "--host=#{@host}",
@@ -5,17 +5,30 @@ require 'rbconfig'
5
5
 
6
6
  module Ports
7
7
  class Recipe < MiniPortile
8
+ attr_writer :gem_platform
9
+
8
10
  def cook
9
- checkpoint = "ports/#{name}-#{version}-#{host}.installed"
11
+ checkpoint = "ports/checkpoints/#{name}-#{version}-#{gem_platform}.installed"
10
12
 
11
13
  unless File.exist? checkpoint
12
14
  super
15
+ FileUtils.mkdir_p("ports/checkpoints")
13
16
  FileUtils.touch checkpoint
14
17
  end
15
18
  end
16
19
 
17
20
  private
18
21
 
22
+ attr_reader :gem_platform
23
+
24
+ def port_path
25
+ "#{@target}/#{gem_platform}/#{@name}/#{@version}"
26
+ end
27
+
28
+ def tmp_path
29
+ "tmp/#{gem_platform}/ports/#{@name}/#{@version}"
30
+ end
31
+
19
32
  def configure_defaults
20
33
  [
21
34
  "--host=#{@host}",
@@ -38,9 +51,9 @@ module Ports
38
51
 
39
52
  def get_patches(libname, version)
40
53
  patches = []
41
-
54
+
42
55
  patch_path = File.expand_path(
43
- File.join('..','..','..','patches',libname,version),
56
+ File.join('..','..','..','patches',libname,version),
44
57
  __FILE__
45
58
  )
46
59
 
@@ -49,4 +62,3 @@ module Ports
49
62
  end
50
63
  end
51
64
  end
52
-
data/tasks/ports.rake CHANGED
@@ -7,63 +7,69 @@ require_relative 'ports/freetds'
7
7
  require_relative '../ext/tiny_tds/extconsts'
8
8
 
9
9
  namespace :ports do
10
- openssl = Ports::Openssl.new(OPENSSL_VERSION)
11
- libiconv = Ports::Libiconv.new(ICONV_VERSION)
12
- freetds = Ports::Freetds.new(FREETDS_VERSION)
10
+ libraries_to_compile = {
11
+ openssl: Ports::Openssl.new(OPENSSL_VERSION),
12
+ libiconv: Ports::Libiconv.new(ICONV_VERSION),
13
+ freetds: Ports::Freetds.new(FREETDS_VERSION)
14
+ }
13
15
 
14
16
  directory "ports"
15
- CLEAN.include "ports/*mingw32*"
17
+ CLEAN.include "ports/*mingw*"
16
18
  CLEAN.include "ports/*.installed"
17
19
 
18
- task :openssl, [:host] do |task, args|
19
- args.with_defaults(host: RbConfig::CONFIG['host'])
20
+ task :openssl, [:host, :gem_platform] do |_task, args|
21
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
20
22
 
21
- openssl.files = [OPENSSL_SOURCE_URI]
22
- openssl.host = args.host
23
- openssl.cook
24
- openssl.activate
23
+ libraries_to_compile[:openssl].files = [OPENSSL_SOURCE_URI]
24
+ libraries_to_compile[:openssl].host = args.host
25
+ libraries_to_compile[:openssl].gem_platform = args.gem_platform
26
+
27
+ libraries_to_compile[:openssl].cook
28
+ libraries_to_compile[:openssl].activate
25
29
  end
26
30
 
27
- task :libiconv, [:host] do |task, args|
28
- args.with_defaults(host: RbConfig::CONFIG['host'])
31
+ task :libiconv, [:host, :gem_platform] do |_task, args|
32
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
29
33
 
30
- libiconv.files = [ICONV_SOURCE_URI]
31
- libiconv.host = args.host
32
- libiconv.cook
33
- libiconv.activate
34
+ libraries_to_compile[:libiconv].files = [ICONV_SOURCE_URI]
35
+ libraries_to_compile[:libiconv].host = args.host
36
+ libraries_to_compile[:libiconv].gem_platform = args.gem_platform
37
+ libraries_to_compile[:libiconv].cook
38
+ libraries_to_compile[:libiconv].activate
34
39
  end
35
40
 
36
- task :freetds, [:host] do |task, args|
37
- args.with_defaults(host: RbConfig::CONFIG['host'])
41
+ task :freetds, [:host, :gem_platform] do |_task, args|
42
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
38
43
 
39
- freetds.files = [FREETDS_SOURCE_URI]
40
- freetds.host = args.host
44
+ libraries_to_compile[:freetds].files = [FREETDS_SOURCE_URI]
45
+ libraries_to_compile[:freetds].host = args.host
46
+ libraries_to_compile[:freetds].gem_platform = args.gem_platform
41
47
 
42
- if openssl
48
+ if libraries_to_compile[:openssl]
43
49
  # freetds doesn't have an option that will provide an rpath
44
50
  # so we do it manually
45
- ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{openssl.path}/lib"
51
+ ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{libraries_to_compile[:openssl].path}/lib"
46
52
  # Add the pkgconfig file with MSYS2'ish path, to prefer our ports build
47
53
  # over MSYS2 system OpenSSL.
48
- ENV['PKG_CONFIG_PATH'] = "#{openssl.path.gsub(/^(\w):/i){"/"+$1.downcase}}/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
49
- freetds.configure_options << "--with-openssl=#{openssl.path}"
54
+ ENV['PKG_CONFIG_PATH'] = "#{libraries_to_compile[:openssl].path.gsub(/^(\w):/i) { "/" + $1.downcase }}/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
55
+ libraries_to_compile[:freetds].configure_options << "--with-openssl=#{libraries_to_compile[:openssl].path}"
50
56
  end
51
57
 
52
- if libiconv
53
- freetds.configure_options << "--with-libiconv-prefix=#{libiconv.path}"
58
+ if libraries_to_compile[:libiconv]
59
+ libraries_to_compile[:freetds].configure_options << "--with-libiconv-prefix=#{libraries_to_compile[:libiconv].path}"
54
60
  end
55
61
 
56
- freetds.cook
57
- freetds.activate
62
+ libraries_to_compile[:freetds].cook
63
+ libraries_to_compile[:freetds].activate
58
64
  end
59
65
 
60
- task :compile, [:host] do |task,args|
61
- args.with_defaults(host: RbConfig::CONFIG['host'])
66
+ task :compile, [:host, :gem_platform] do |_task, args|
67
+ args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
62
68
 
63
- puts "Compiling ports for #{args.host}..."
69
+ puts "Compiling ports for #{args.host} (Ruby platform #{args.gem_platform}) ..."
64
70
 
65
- ['openssl','libiconv','freetds'].each do |lib|
66
- Rake::Task["ports:#{lib}"].invoke(args.host)
71
+ libraries_to_compile.keys.each do |lib|
72
+ Rake::Task["ports:#{lib}"].invoke(args.host, args.gem_platform)
67
73
  end
68
74
  end
69
75
 
@@ -72,13 +78,30 @@ namespace :ports do
72
78
  require 'rake_compiler_dock'
73
79
 
74
80
  # build the ports for all our cross compile hosts
75
- GEM_PLATFORM_HOSTS.each do |gem_platform, host|
81
+ GEM_PLATFORM_HOSTS.each do |gem_platform, meta|
76
82
  # make sure to install our bundle
77
83
  build = ['bundle']
78
- build << "rake ports:compile[#{host}] MAKE='make -j`nproc`'"
84
+ build << "RUBY_CC_VERSION=#{meta[:ruby_versions]} rake ports:compile[#{meta[:host]},#{gem_platform}] MAKE='make -j`nproc`'"
79
85
  RakeCompilerDock.sh build.join(' && '), platform: gem_platform
80
86
  end
81
87
  end
88
+
89
+ desc "Notes the actual versions for the compiled ports into a file"
90
+ task "version_file", [:gem_platform] do |_task, args|
91
+ args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
92
+
93
+ ports_version = {}
94
+
95
+ libraries_to_compile.each do |library, library_recipe|
96
+ ports_version[library] = library_recipe.version
97
+ end
98
+
99
+ ports_version[:platform] = args.gem_platform
100
+
101
+ File.open(".ports_versions", "w") do |f|
102
+ f.write ports_version
103
+ end
104
+ end
82
105
  end
83
106
 
84
107
  desc 'Build ports and activate libraries for the current architecture.'
@@ -0,0 +1,31 @@
1
+ $ProgressPreference = 'SilentlyContinue'
2
+
3
+ if (-not(Test-path "C:\Downloads"))
4
+ {
5
+ mkdir "C:\Downloads"
6
+ }
7
+
8
+ $sqlInstallationFile = "C:\Downloads\sqlexpress.exe"
9
+ if (-not(Test-path $sqlInstallationFile -PathType leaf))
10
+ {
11
+ Write-Host "Downloading SQL Express ..."
12
+ Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=829176" -OutFile "C:\Downloads\sqlexpress.exe"
13
+ }
14
+
15
+ Write-Host "Installing SQL Express ..."
16
+ Start-Process -Wait -FilePath "C:\Downloads\sqlexpress.exe" -ArgumentList /qs, /x:"C:\Downloads\setup"
17
+ C:\Downloads\setup\setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS
18
+
19
+ Write-Host "Configuring SQL Express ..."
20
+ stop-service MSSQL`$SQLEXPRESS
21
+ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value ''
22
+ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433
23
+ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2
24
+
25
+ Write-Host "Starting SQL Express ..."
26
+ start-service MSSQL`$SQLEXPRESS
27
+
28
+ Write-Host "Configuring MSSQL for TinyTDS ..."
29
+ & sqlcmd -Q "CREATE DATABASE [tinytdstest];"
30
+ & sqlcmd -Q "CREATE LOGIN [tinytds] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [tinytdstest];"
31
+ & sqlcmd -Q "USE [tinytdstest]; CREATE USER [tinytds] FOR LOGIN [tinytds]; EXEC sp_addrolemember N'db_owner', N'tinytds';"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
7
+ curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
8
+ sudo apt-get update
9
+ sudo ACCEPT_EULA=Y apt-get -y install mssql-tools unixodbc-dev
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i ./test/sql/db-create.sql
7
+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i ./test/sql/db-login.sql
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+
5
+ sudo groupadd -g 3434 circleci_tinytds
6
+ sudo usermod -a -G circleci_tinytds $USER
7
+ sudo useradd circleci_tinytds -u 3434 -g 3434
8
+ sudo usermod -a -G circleci_tinytds circleci_tinytds
9
+ sudo chgrp -R circleci_tinytds .
10
+ sudo chmod -R g+rwx .
data/test/client_test.rb CHANGED
@@ -16,6 +16,7 @@ class ClientTest < TinyTds::TestCase
16
16
  assert @client.close
17
17
  assert @client.closed?
18
18
  assert !@client.active?
19
+ assert @client.dead?
19
20
  action = lambda { @client.execute('SELECT 1 as [one]').each }
20
21
  assert_raise_tinytds_error(action) do |e|
21
22
  assert_match %r{closed connection}i, e.message, 'ignore if non-english test run'
@@ -133,9 +134,8 @@ class ClientTest < TinyTds::TestCase
133
134
  end
134
135
 
135
136
  it 'raises TinyTds exception with tcp socket network failure' do
136
- skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
137
137
  begin
138
- client = new_connection timeout: 2, port: 1234
138
+ client = new_connection timeout: 2, port: 1234, host: ENV['TOXIPROXY_HOST']
139
139
  assert_client_works(client)
140
140
  action = lambda { client.execute("waitfor delay '00:00:05'").do }
141
141
 
@@ -155,9 +155,10 @@ class ClientTest < TinyTds::TestCase
155
155
  end
156
156
 
157
157
  it 'raises TinyTds exception with dead connection network failure' do
158
- skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
158
+ skip if ruby_windows?
159
+
159
160
  begin
160
- client = new_connection timeout: 2, port: 1234
161
+ client = new_connection timeout: 2, port: 1234, host: ENV['TOXIPROXY_HOST']
161
162
  assert_client_works(client)
162
163
  action = lambda { client.execute("waitfor delay '00:00:05'").do }
163
164
 
@@ -177,11 +178,10 @@ class ClientTest < TinyTds::TestCase
177
178
  end
178
179
 
179
180
  it 'raises TinyTds exception with login timeout' do
180
- skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
181
181
  begin
182
182
  action = lambda do
183
183
  Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
184
- new_connection login_timeout: 1, port: 1234
184
+ new_connection login_timeout: 1, port: 1234, host: ENV['TOXIPROXY_HOST']
185
185
  end
186
186
  end
187
187
  assert_raise_tinytds_error(action) do |e|
data/test/gem_test.rb CHANGED
@@ -9,11 +9,11 @@ class GemTest < MiniTest::Spec
9
9
 
10
10
  # We're going to muck with some system globals so lets make sure
11
11
  # they get set back later
12
- original_host = RbConfig::CONFIG['host']
12
+ original_platform = RbConfig::CONFIG['arch']
13
13
  original_pwd = Dir.pwd
14
14
 
15
15
  after do
16
- RbConfig::CONFIG['host'] = original_host
16
+ RbConfig::CONFIG['arch'] = original_platform
17
17
  Dir.chdir original_pwd
18
18
  end
19
19
 
@@ -61,7 +61,7 @@ class GemTest < MiniTest::Spec
61
61
  end
62
62
 
63
63
  before do
64
- RbConfig::CONFIG['host'] = 'fake-host-with-dirs'
64
+ RbConfig::CONFIG['arch'] = 'fake-host-with-dirs'
65
65
  fake_bin_paths.each do |path|
66
66
  FileUtils.mkdir_p(path)
67
67
  end
@@ -85,7 +85,7 @@ class GemTest < MiniTest::Spec
85
85
 
86
86
  describe 'when the ports directories are missing' do
87
87
  before do
88
- RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
88
+ RbConfig::CONFIG['arch'] = 'fake-host-without-dirs'
89
89
  end
90
90
 
91
91
  it 'should return no directories' do
@@ -115,7 +115,7 @@ class GemTest < MiniTest::Spec
115
115
  end
116
116
 
117
117
  before do
118
- RbConfig::CONFIG['host'] = 'fake-host-with-dirs'
118
+ RbConfig::CONFIG['arch'] = 'fake-host-with-dirs'
119
119
  fake_lib_paths.each do |path|
120
120
  FileUtils.mkdir_p(path)
121
121
  end
@@ -139,7 +139,7 @@ class GemTest < MiniTest::Spec
139
139
 
140
140
  describe 'when the ports directories are missing' do
141
141
  before do
142
- RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
142
+ RbConfig::CONFIG['arch'] = 'fake-host-without-dirs'
143
143
  end
144
144
 
145
145
 
@@ -156,16 +156,14 @@ class GemTest < MiniTest::Spec
156
156
 
157
157
  describe '#ports_host' do
158
158
  {
159
- 'i686-pc-linux-gnu' => 'i686-pc-linux-gnu',
160
- 'x86_64-pc-linux-gnu' => 'x86_64-pc-linux-gnu',
161
- 'i686-w64-mingw32' => 'i686-w64-mingw32',
162
- 'x86_64-w64-mingw32' => 'x86_64-w64-mingw32',
163
- # consolidate this host to our build w64-mingw32 arch
164
- 'i686-pc-mingw32' => 'i686-w64-mingw32'
159
+ 'x64-mingw-ucrt' => 'x64-mingw-ucrt',
160
+ 'x64-mingw32' => 'x64-mingw32',
161
+ 'x86-mingw32' => 'x86-mingw32',
162
+ 'x86_64-linux' => 'x86_64-linux',
165
163
  }.each do |host,expected|
166
164
  describe "on a #{host} architecture" do
167
165
  before do
168
- RbConfig::CONFIG['host'] = host
166
+ RbConfig::CONFIG['arch'] = host
169
167
  end
170
168
 
171
169
  it "should return a #{expected} ports host" do
@@ -0,0 +1,18 @@
1
+ :ON ERROR EXIT
2
+
3
+ PRINT 'RUNNING DB-CREATE.SQL, CREATING TINYTDS TEST DATABASE';
4
+ IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'tinytdstest')
5
+ BEGIN
6
+ CREATE DATABASE [tinytdstest];
7
+ END
8
+ GO
9
+
10
+ IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name LIKE 'tinytdstest')
11
+ BEGIN
12
+ PRINT 'TINY TDS TEST DB SUCCESSFULY CREATED';
13
+ END
14
+ ELSE
15
+ BEGIN
16
+ THROW 51000, 'TINY TDS TEST DB CREATION FAILED', 1;
17
+ END
18
+ GO
@@ -0,0 +1,38 @@
1
+ :ON ERROR EXIT
2
+
3
+ PRINT 'RUNNING DB-LOGIN.SQL';
4
+
5
+ PRINT 'CREATING TINYTDS TEST LOGIN';
6
+ IF NOT EXISTS (select name from sys.server_principals where name like 'tinytds')
7
+ BEGIN
8
+ CREATE LOGIN [tinytds] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [tinytdstest];
9
+ END
10
+ GO
11
+
12
+ IF EXISTS (select name from sys.server_principals where name like 'tinytds')
13
+ BEGIN
14
+ PRINT 'TINY TDS TEST LOGIN SUCCESSFULY CREATED';
15
+ END
16
+ ELSE
17
+ BEGIN
18
+ THROW 51000, 'TINY TDS TEST LOGIN CREATION FAILED', 1;
19
+ END
20
+ GO
21
+
22
+ USE [tinytdstest];
23
+ IF NOT EXISTS (select name from sys.database_principals where name LIKE 'tinytds')
24
+ BEGIN
25
+ CREATE USER [tinytds] FOR LOGIN [tinytds];
26
+ EXEC sp_addrolemember N'db_owner', N'tinytds';
27
+ END
28
+ GO
29
+
30
+ IF EXISTS (select name from sys.database_principals where name LIKE 'tinytds')
31
+ BEGIN
32
+ PRINT 'TINY TDS TEST USER SUCCESSFULY CREATED';
33
+ END
34
+ ELSE
35
+ BEGIN
36
+ THROW 51000, 'TINY TDS TEST USER CREATION FAILED', 1;
37
+ END
38
+ GO
data/test/test_helper.rb CHANGED
@@ -248,22 +248,31 @@ module TinyTds
248
248
  end
249
249
 
250
250
  def init_toxiproxy
251
- return if ENV['APPVEYOR_BUILD_FOLDER'] # only for CI using docker
252
-
253
251
  # In order for toxiproxy to work for local docker instances of mssql, the containers must be on the same network
254
252
  # and the host used below must match the mssql container name so toxiproxy knows where to proxy to.
255
253
  # localhost from the perspective of toxiproxy's container is its own container an *not* the mssql container it needs to proxy to.
256
254
  # docker-compose.yml handles this automatically for us. In instances where someone is using their own local mssql container they'll
257
255
  # need to set up the networks manually and set TINYTDS_UNIT_HOST to their mssql container name
258
256
  # For anything other than localhost just use the environment config
259
- env_host = ENV['TINYTDS_UNIT_HOST_TEST'] || ENV['TINYTDS_UNIT_HOST'] || 'localhost'
260
- host = ['localhost', '127.0.0.1', '0.0.0.0'].include?(env_host) ? 'sqlserver' : env_host
261
- port = ENV['TINYTDS_UNIT_PORT'] || 1433
257
+ toxi_host = ENV['TOXIPROXY_HOST'] || 'localhost'
258
+ toxi_api_port = 8474
259
+ toxi_test_port = 1234
260
+ Toxiproxy.host = "http://#{toxi_host}:#{toxi_api_port}"
261
+
262
+ toxi_upstream_host = ENV['TINYTDS_UNIT_HOST_TEST'] || ENV['TINYTDS_UNIT_HOST'] || 'localhost'
263
+ toxi_upstream_port = ENV['TINYTDS_UNIT_PORT'] || 1433
264
+
265
+ puts "\n-------------------------"
266
+ puts "Toxiproxy api listener: #{toxi_host}:#{toxi_api_port}"
267
+ puts "Toxiproxy unit test listener: #{toxi_host}:#{toxi_test_port}"
268
+ puts "Toxiproxy upstream sqlserver: #{toxi_upstream_host}:#{toxi_upstream_port}"
269
+ puts '-------------------------'
270
+
262
271
  Toxiproxy.populate([
263
272
  {
264
273
  name: "sqlserver_test",
265
- listen: "0.0.0.0:1234",
266
- upstream: "#{host}:#{port}"
274
+ listen: "#{toxi_host}:#{toxi_test_port}",
275
+ upstream: "#{toxi_upstream_host}:#{toxi_upstream_port}"
267
276
  }
268
277
  ])
269
278
  end
data/tiny_tds.gemspec CHANGED
@@ -20,11 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.license = 'MIT'
21
21
  s.required_ruby_version = '>= 2.0.0'
22
22
  s.metadata['msys2_mingw_dependencies'] = 'freetds'
23
- s.add_development_dependency 'mini_portile2', '~> 2.0'
24
- s.add_development_dependency 'rake', '~> 13.0'
25
- s.add_development_dependency 'rake-compiler', '~> 1.0'
26
- s.add_development_dependency 'rake-compiler-dock', '~> 1.0'
27
- s.add_development_dependency 'minitest', '~> 5.6'
28
- s.add_development_dependency 'connection_pool', '~> 2.2'
23
+ s.add_development_dependency 'mini_portile2', '~> 2.5.0'
24
+ s.add_development_dependency 'rake', '~> 13.0.0'
25
+ s.add_development_dependency 'rake-compiler', '~> 1.2'
26
+ s.add_development_dependency 'rake-compiler-dock', '~> 1.3.0'
27
+ s.add_development_dependency 'minitest', '~> 5.14.0'
28
+ s.add_development_dependency 'minitest-ci', '~> 3.4.0'
29
+ s.add_development_dependency 'connection_pool', '~> 2.2.0'
29
30
  s.add_development_dependency 'toxiproxy', '~> 2.0.0'
30
31
  end