Skip to content

Commit

Permalink
Introduce JDBC Tests for MSSQL
Browse files Browse the repository at this point in the history
- Added table names to query, required for jdbc
- Created integration test for jdbc integration tests following existing pattern
- updated dockerfile to import custom java jar locally
  • Loading branch information
BradleyBoutcher committed Feb 4, 2020
1 parent 5e4d5cb commit 8ab5e84
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
16 changes: 16 additions & 0 deletions test/connector/tcp/mssql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ RUN rm -rf /etc/apt/sources.list.d/mssql-release.list && \
# Add python 3 and pyodbc
RUN apt-get install -y python3 python3-pip
RUN pip3 install pyodbc

# Add java8 and add to $PATH
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;

# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
6 changes: 5 additions & 1 deletion test/connector/tcp/mssql/mssql_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func TestMSSQLConnector(t *testing.T) {
RunConnectivityTests(t, pythonODBCExec)
})

t.Run("java-JDBC", func(t *testing.T) {
RunConnectivityTests(t, javaJDBCExec)
})

t.Run("go-mssql", func(t *testing.T) {
RunConnectivityTests(t, gomssqlExec)
})
Expand All @@ -35,7 +39,7 @@ func RunConnectivityTests(t *testing.T, queryExec dbQueryExecutor) {
// Execute Query
out, err := queryExec(
defaultSecretlessDbConfig(),
fmt.Sprintf("select %s, '%s'", testInt, testString),
fmt.Sprintf("SELECT %s AS sum, '%s' AS str", testInt, testString),
)

// Test the returned values
Expand Down
41 changes: 41 additions & 0 deletions test/connector/tcp/mssql/mssql_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,47 @@ func pythonODBCExec(
return string(out), nil
}

// runs queries using Java JDBC
// Jar modified from this source: http://jdbcsql.sourceforge.net/
func javaJDBCExec(
cfg dbConfig,
query string,
) (string, error) {
const jdbcJARPath = "/secretless/test/util/jdbc/jdbc.jar"

args := []string{
"-jar", jdbcJARPath,
"-m", "mssql",
"-h", fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
"-U", cfg.Username,
"-P", cfg.Password,
}

// For JDBC, database is not optional. If empty, add teh default MsSQL database
if db := cfg.Database; db == "" {
args = append(args, "-d", "tempdb")
} else {
args = append(args, "-d", db)
}

args = append(args, query)

out, err := exec.Command(
"java",
args...,
).Output()

if err != nil {
if exitErrr, ok := err.(*exec.ExitError); ok {
return "", errors.New(string(exitErrr.Stderr))
}

return "", err
}

return string(out), nil
}

// runs queries using go-mssqldb
func gomssqlExec(
cfg dbConfig,
Expand Down
Binary file added test/util/jdbc/jdbc.jar
Binary file not shown.

0 comments on commit 8ab5e84

Please sign in to comment.