summaryrefslogtreecommitdiffstats
path: root/ldap_test.go
diff options
context:
space:
mode:
authortmfkams <tmfkams@gmail.com>2014-01-19 23:04:16 +0100
committerSamuel Stauffer <samuel@descolada.com>2014-03-19 21:57:58 +0100
commite45f83457931e08f9f6d5aec48f51fd390a01eb8 (patch)
treed95a79f94932115bf5c0441f2eeb520959bbda0d /ldap_test.go
parentMerge pull request #4 from bollenberger/master (diff)
downloadldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.gz
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.bz2
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.lz
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.xz
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.zst
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.zip
Diffstat (limited to 'ldap_test.go')
-rw-r--r--ldap_test.go216
1 files changed, 108 insertions, 108 deletions
diff --git a/ldap_test.go b/ldap_test.go
index 708dde6..f21a8a6 100644
--- a/ldap_test.go
+++ b/ldap_test.go
@@ -1,125 +1,125 @@
package ldap
import (
- "fmt"
- "testing"
+ "fmt"
+ "testing"
)
var ldap_server string = "ldap.itd.umich.edu"
var ldap_port uint16 = 389
var base_dn string = "dc=umich,dc=edu"
-var filter []string = []string {
- "(cn=cis-fac)",
- "(&(objectclass=rfc822mailgroup)(cn=*Computer*))",
- "(&(objectclass=rfc822mailgroup)(cn=*Mathematics*))" }
-var attributes []string = []string {
- "cn",
- "description" }
-
-func TestConnect( t *testing.T ) {
- fmt.Printf( "TestConnect: starting...\n" )
- l, err := Dial( "tcp", fmt.Sprintf( "%s:%d", ldap_server, ldap_port ) )
- if err != nil {
- t.Errorf( err.String() )
- return
- }
- defer l.Close()
- fmt.Printf( "TestConnect: finished...\n" )
+var filter []string = []string{
+ "(cn=cis-fac)",
+ "(&(objectclass=rfc822mailgroup)(cn=*Computer*))",
+ "(&(objectclass=rfc822mailgroup)(cn=*Mathematics*))"}
+var attributes []string = []string{
+ "cn",
+ "description"}
+
+func TestConnect(t *testing.T) {
+ fmt.Printf("TestConnect: starting...\n")
+ l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldap_server, ldap_port))
+ if err != nil {
+ t.Errorf(err.String())
+ return
+ }
+ defer l.Close()
+ fmt.Printf("TestConnect: finished...\n")
}
-func TestSearch( t *testing.T ) {
- fmt.Printf( "TestSearch: starting...\n" )
- l, err := Dial( "tcp", fmt.Sprintf( "%s:%d", ldap_server, ldap_port ) )
- if err != nil {
- t.Errorf( err.String() )
- return
- }
- defer l.Close()
-
- search_request := NewSearchRequest(
- base_dn,
- ScopeWholeSubtree, DerefAlways, 0, 0, false,
- filter[0],
- attributes,
- nil )
-
- sr, err := l.Search( search_request )
- if err != nil {
- t.Errorf( err.String() )
- return
- }
-
- fmt.Printf( "TestSearch: %s -> num of entries = %d\n", search_request.Filter, len( sr.Entries ) )
+func TestSearch(t *testing.T) {
+ fmt.Printf("TestSearch: starting...\n")
+ l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldap_server, ldap_port))
+ if err != nil {
+ t.Errorf(err.String())
+ return
+ }
+ defer l.Close()
+
+ search_request := NewSearchRequest(
+ base_dn,
+ ScopeWholeSubtree, DerefAlways, 0, 0, false,
+ filter[0],
+ attributes,
+ nil)
+
+ sr, err := l.Search(search_request)
+ if err != nil {
+ t.Errorf(err.String())
+ return
+ }
+
+ fmt.Printf("TestSearch: %s -> num of entries = %d\n", search_request.Filter, len(sr.Entries))
}
-func TestSearchWithPaging( t *testing.T ) {
- fmt.Printf( "TestSearchWithPaging: starting...\n" )
- l, err := Dial( "tcp", fmt.Sprintf( "%s:%d", ldap_server, ldap_port ) )
- if err != nil {
- t.Errorf( err.String() )
- return
- }
- defer l.Close()
-
- err = l.Bind( "", "" )
- if err != nil {
- t.Errorf( err.String() )
- return
- }
-
- search_request := NewSearchRequest(
- base_dn,
- ScopeWholeSubtree, DerefAlways, 0, 0, false,
- filter[1],
- attributes,
- nil )
- sr, err := l.SearchWithPaging( search_request, 5 )
- if err != nil {
- t.Errorf( err.String() )
- return
- }
-
- fmt.Printf( "TestSearchWithPaging: %s -> num of entries = %d\n", search_request.Filter, len( sr.Entries ) )
+func TestSearchWithPaging(t *testing.T) {
+ fmt.Printf("TestSearchWithPaging: starting...\n")
+ l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldap_server, ldap_port))
+ if err != nil {
+ t.Errorf(err.String())
+ return
+ }
+ defer l.Close()
+
+ err = l.Bind("", "")
+ if err != nil {
+ t.Errorf(err.String())
+ return
+ }
+
+ search_request := NewSearchRequest(
+ base_dn,
+ ScopeWholeSubtree, DerefAlways, 0, 0, false,
+ filter[1],
+ attributes,
+ nil)
+ sr, err := l.SearchWithPaging(search_request, 5)
+ if err != nil {
+ t.Errorf(err.String())
+ return
+ }
+
+ fmt.Printf("TestSearchWithPaging: %s -> num of entries = %d\n", search_request.Filter, len(sr.Entries))
}
-func testMultiGoroutineSearch( t *testing.T, l *Conn, results chan *SearchResult, i int ) {
- search_request := NewSearchRequest(
- base_dn,
- ScopeWholeSubtree, DerefAlways, 0, 0, false,
- filter[i],
- attributes,
- nil )
- sr, err := l.Search( search_request )
-
- if err != nil {
- t.Errorf( err.String() )
- results <- nil
- return
- }
-
- results <- sr
+func testMultiGoroutineSearch(t *testing.T, l *Conn, results chan *SearchResult, i int) {
+ search_request := NewSearchRequest(
+ base_dn,
+ ScopeWholeSubtree, DerefAlways, 0, 0, false,
+ filter[i],
+ attributes,
+ nil)
+ sr, err := l.Search(search_request)
+
+ if err != nil {
+ t.Errorf(err.String())
+ results <- nil
+ return
+ }
+
+ results <- sr
}
-func TestMultiGoroutineSearch( t *testing.T ) {
- fmt.Printf( "TestMultiGoroutineSearch: starting...\n" )
- l, err := Dial( "tcp", fmt.Sprintf( "%s:%d", ldap_server, ldap_port ) )
- if err != nil {
- t.Errorf( err.String() )
- return
- }
- defer l.Close()
-
- results := make( []chan *SearchResult, len( filter ) )
- for i := range filter {
- results[ i ] = make( chan *SearchResult )
- go testMultiGoroutineSearch( t, l, results[ i ], i )
- }
- for i := range filter {
- sr := <-results[ i ]
- if sr == nil {
- t.Errorf( "Did not receive results from goroutine for %q", filter[ i ] )
- } else {
- fmt.Printf( "TestMultiGoroutineSearch(%d): %s -> num of entries = %d\n", i, filter[ i ], len( sr.Entries ) )
- }
- }
+func TestMultiGoroutineSearch(t *testing.T) {
+ fmt.Printf("TestMultiGoroutineSearch: starting...\n")
+ l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldap_server, ldap_port))
+ if err != nil {
+ t.Errorf(err.String())
+ return
+ }
+ defer l.Close()
+
+ results := make([]chan *SearchResult, len(filter))
+ for i := range filter {
+ results[i] = make(chan *SearchResult)
+ go testMultiGoroutineSearch(t, l, results[i], i)
+ }
+ for i := range filter {
+ sr := <-results[i]
+ if sr == nil {
+ t.Errorf("Did not receive results from goroutine for %q", filter[i])
+ } else {
+ fmt.Printf("TestMultiGoroutineSearch(%d): %s -> num of entries = %d\n", i, filter[i], len(sr.Entries))
+ }
+ }
}