Commit bdfa295b authored by ale's avatar ale

Move ldap test server to its own package

parent 23b73199
......@@ -4,8 +4,10 @@ import (
"context"
"testing"
"git.autistici.org/ai3/accountserver"
"github.com/go-test/deep"
"git.autistici.org/ai3/accountserver"
"git.autistici.org/ai3/accountserver/ldaptest"
)
const (
......@@ -15,7 +17,8 @@ const (
)
func startServerAndGetUser(t testing.TB) (func(), accountserver.Backend, *accountserver.User) {
stop := startTestLDAPServer(t, &testLDAPServerConfig{
stop := ldaptest.StartServer(t, &ldaptest.Config{
Dir: "../ldaptest",
Port: testLDAPPort,
Base: "dc=example,dc=com",
LDIFs: []string{"testdata/base.ldif", "testdata/test1.ldif"},
......@@ -132,7 +135,8 @@ func TestModel_GetUser_Resources(t *testing.T) {
}
func TestModel_SetResourceStatus(t *testing.T) {
stop := startTestLDAPServer(t, &testLDAPServerConfig{
stop := ldaptest.StartServer(t, &ldaptest.Config{
Dir: "../ldaptest",
Port: testLDAPPort,
Base: "dc=example,dc=com",
LDIFs: []string{"testdata/base.ldif", "testdata/test1.ldif"},
......@@ -164,7 +168,8 @@ func TestModel_SetResourceStatus(t *testing.T) {
}
func TestModel_HasAnyResource(t *testing.T) {
stop := startTestLDAPServer(t, &testLDAPServerConfig{
stop := ldaptest.StartServer(t, &ldaptest.Config{
Dir: "../ldaptest",
Port: testLDAPPort,
Base: "dc=example,dc=com",
LDIFs: []string{"testdata/base.ldif", "testdata/test1.ldif"},
......
package backend
package ldaptest
import (
"errors"
......@@ -7,11 +7,14 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
)
type testLDAPServerConfig struct {
// Config for the test in-memory LDAP server.
type Config struct {
Dir string
Base string
Port int
LDIFs []string
......@@ -33,7 +36,8 @@ func waitForPort(port int, timeout time.Duration) error {
}
}
func startTestLDAPServer(t testing.TB, config *testLDAPServerConfig) func() {
// StartServer starts a test LDAP server with the specified configuration.
func StartServer(t testing.TB, config *Config) func() {
tmpf, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
......@@ -47,7 +51,7 @@ ldap.port=%d
args := []string{tmpf.Name()}
args = append(args, config.LDIFs...)
proc := exec.Command("./unboundid-ldap-server/bin/unboundid-ldap-server", args...)
proc := exec.Command(filepath.Join(config.Dir, "unboundid-ldap-server/bin/unboundid-ldap-server"), args...)
proc.Stdout = os.Stdout
proc.Stderr = os.Stderr
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment