summaryrefslogtreecommitdiffstats
path: root/filter_test.go
diff options
context:
space:
mode:
authorVincent Vanackere <vincent.vanackere@gmail.com>2014-08-01 22:04:17 +0200
committerVincent Vanackere <vincent.vanackere@gmail.com>2014-08-01 22:04:17 +0200
commitacf536b08dcc4c46588c2e47ab64eddd4849f781 (patch)
tree4bbd826ebd6f805fcb8dc41454483d9b8e5a6c71 /filter_test.go
parentfilter : small code cleanup (diff)
downloadldap-acf536b08dcc4c46588c2e47ab64eddd4849f781.tar
ldap-acf536b08dcc4c46588c2e47ab64eddd4849f781.tar.gz
ldap-acf536b08dcc4c46588c2e47ab64eddd4849f781.tar.bz2
ldap-acf536b08dcc4c46588c2e47ab64eddd4849f781.tar.lz
ldap-acf536b08dcc4c46588c2e47ab64eddd4849f781.tar.xz
ldap-acf536b08dcc4c46588c2e47ab64eddd4849f781.tar.zst
ldap-acf536b08dcc4c46588c2e47ab64eddd4849f781.zip
Diffstat (limited to 'filter_test.go')
-rw-r--r--filter_test.go55
1 files changed, 27 insertions, 28 deletions
diff --git a/filter_test.go b/filter_test.go
index e78caa1..a771cff 100644
--- a/filter_test.go
+++ b/filter_test.go
@@ -1,6 +1,7 @@
package ldap
import (
+ "reflect"
"testing"
"github.com/vanackere/asn1-ber"
@@ -45,39 +46,37 @@ func TestFilter(t *testing.T) {
}
}
-func TestDecodePresentFilter(t *testing.T) {
-
- bs := []byte{0x87, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72} // ~ (member=*)
-
- p := ber.DecodePacket(bs)
- f, err := DecompileFilter(p)
- if err != nil {
- t.Errorf("--- CAN'T DECODE & DECOMPILE FILTER")
- return
- }
- if f != "(member=*)" {
- t.Errorf("expected (member=*), got %s", f)
- }
+type binTestFilter struct {
+ bin []byte
+ str string
+}
+var binTestFilters = []binTestFilter{
+ {bin: []byte{0x87, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72}, str: "(member=*)"},
}
-func TestEncodeDecodePresentFilter(t *testing.T) {
- f := "(member=*)"
- p, err := CompileFilter(f)
- if err != nil {
- t.Errorf("cant compile filter")
- return
+func TestFiltersDecode(t *testing.T) {
+ for i, test := range binTestFilters {
+ p := ber.DecodePacket(test.bin)
+ if filter, err := DecompileFilter(p); err != nil {
+ t.Errorf("binTestFilters[%d], DecompileFilter returned : %s", i, err)
+ } else if filter != test.str {
+ t.Errorf("binTestFilters[%d], %q expected, got %q", i, test.str, filter)
+ }
}
- bytes := p.Bytes()
+}
- p2 := ber.DecodePacket(bytes)
- f2, err := DecompileFilter(p2)
- if err != nil {
- t.Errorf("cant decompile filter")
- return
- }
- if f != f2 {
- t.Errorf("encode/decode changed filter")
+func TestFiltersEncode(t *testing.T) {
+ for i, test := range binTestFilters {
+ p, err := CompileFilter(test.str)
+ if err != nil {
+ t.Errorf("binTestFilters[%d], CompileFilter returned : %s", i, err)
+ continue
+ }
+ b := p.Bytes()
+ if !reflect.DeepEqual(b, test.bin) {
+ t.Errorf("binTestFilters[%d], %q expected for CompileFilter(%q), got %q", i, test.bin, test.str, b)
+ }
}
}