alexbrainman / odbc

odbc driver written in go
BSD 3-Clause "New" or "Revised" License
352 stars 140 forks source link

Testing sql server easily on Debian/Ubuntu #136

Closed dolanor closed 5 years ago

dolanor commented 5 years ago

SQL Server is not an easy target to test when you don't even own a Windows system. So I checked for vagrant images and then, with the new dynamics of Microsoft, I thought that maybe they put a docker image out there. There is! So here is my little attempt to make that testing easy with the littlest dependencies you need to make it work on debian/ubuntu.

https://gist.github.com/dolanor/8af1950b32a77c90dad9cbb2aaf63ed6

#!/bin/bash

set -e

cid=`docker run --name go-odbc-mssql-server -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=notVERYstrongP455word.' -d mcr.microsoft.com/mssql/server:2017-CU8-ubuntu`
mssqlIP=$(docker inspect --format "{{ .NetworkSettings.Networks.bridge.IPAddress }}" ${cid})
docker run --rm -it golang:1.12 sh -c "
apt update
apt install -y tdsodbc unixodbc-dev freetds-bin
cat > /etc/odbcinst.ini << EOF
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
EOF
go get -v -t -d github.com/alexbrainman/odbc
cd /go/src/github.com/alexbrainman/odbc/
go test -run=MS -mssrv=${mssqlIP} -msdb=master -msport=1433 -msdriver=freetds -mspass=notVERYstrongP455word. -msuser=SA"
docker rm -f ${cid}

I didn't know what exactly to do with it, so here is this "issue", but maybe it has its place in the wiki, and maybe we could make some integration test out of it?

alexbrainman commented 5 years ago

So here is my little attempt to make that testing easy with the littlest dependencies you need to make it work on debian/ubuntu.

Same problem here. But I created $GOPATH/src/github.com/alexbrainman/odbc/Makefile that allows me to quickly have MSSQL server running on my Linux computer.

Unlike your script, I run go test on my Linux (or my Windows) computer, not inside Docker. I do that when I develop or debug github.com/alexbrainman/odbc. The only problem with my approach is that I have to have unixodbc and freetds installed on my Linux computer. But your script above gives me some ideas on how to create Docker image with unixodbc and freetds installed - this way I will be able to develop on any Linux computer. Next time I need to run tests, I will try to build that Docker image.

maybe it has its place in the wiki, and maybe we could make some integration test out of it?

I have very little free time now days. And I rarely need to fiddle with this package. But, if you like to add wiki page or create some integration, please, go ahead. I will help as much as my time allows it.

Thank you.

Alex

dolanor commented 5 years ago

I feel embarrassed that I didn't even read the Makefile and saw you were already testing it… But you have a point in the fact that having the docker image with all the odbc/freetds install could help testing the setup more easily! I'll close that for now and create a PR when I have an idea how to make that.

alexbrainman commented 5 years ago

I'll close that for now and create a PR when I have an idea how to make that.

SGTM

Alex