* [THOG-162] Implement JDBC verification for select drivers Also includes integration tests for postgres and mysql via docker. To run, execute the following (untested what will happen if the docker images aren't installed): go test -tags=detectors,integration ./pkg/detectors/jdbc * Make jdbc regex a bit more strict * Surface the context to allow the caller to set a timeout
47 lines
773 B
Go
47 lines
773 B
Go
//go:build detectors
|
|
// +build detectors
|
|
|
|
package jdbc
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func parseSqliteTest(subname string) (jdbc, error) {
|
|
j, err := parseSqlite(subname)
|
|
if err != nil {
|
|
return j, err
|
|
}
|
|
j.(*sqliteJDBC).testing = true
|
|
return j, err
|
|
}
|
|
|
|
func TestParseSqlite(t *testing.T) {
|
|
type testStruct struct {
|
|
input string
|
|
wantErr bool
|
|
}
|
|
tests := []struct {
|
|
input string
|
|
wantErr bool
|
|
}{
|
|
{input: "", wantErr: true},
|
|
{input: ":memory:"},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.input, func(t *testing.T) {
|
|
j, err := parseSqliteTest(test.input)
|
|
if test.wantErr {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.True(t, j.ping(context.Background()))
|
|
}
|
|
})
|
|
}
|
|
}
|