forked from JesseCoretta/go-aci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_test.go
1432 lines (1162 loc) · 41.2 KB
/
filter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package aci
import (
"fmt"
"testing"
)
func TestSearchFilter_setFromVar(t *testing.T) {
want := `(&(objectClass=employee)(cn=Jesse Coretta))`
var f SearchFilter
_ = f.Eq()
_ = f.Ne()
// for codecov (check panic potential)
if empty := f.String(); empty != `` {
t.Errorf("%T failed: [%T.String]; should be empty",
t.Name(), f)
return
}
// for codecov (zero string set)
f.Set(``)
if err := f.Eq().Valid(); err == nil {
t.Errorf("%T failed: [%T.Eq]; no error",
t.Name(), f)
return
}
if err := f.Ne().Valid(); err == nil {
t.Errorf("%T failed: [%T.Eq]; no error",
t.Name(), f)
return
}
f.Set(want)
if want != f.String() {
t.Errorf("%T failed [Filter]:\nwant '%s'\ngot '%s'",
t.Name(), want, f)
return
}
}
func TestFilter(t *testing.T) {
raw := `(&(objectClass=employee)(cn=Jesse Coretta))`
want := raw
f := Filter(raw)
if want != f.String() {
t.Errorf("%T failed [Filter]:\nwant '%s'\ngot '%s'",
t.Name(), want, f)
return
}
c := f.Eq()
want = sprintf("( targetfilter = %q )", raw)
if want != c.String() {
t.Errorf("%T failed [SearchFilter.Eq]:\nwant '%s'\ngot '%s'",
t.Name(), want, f)
return
}
c = f.Ne()
want = sprintf("( targetfilter != %q )", raw)
if want != c.String() {
t.Errorf("%T failed [SearchFilter.Ne]:\nwant '%s'\ngot '%s'",
t.Name(), want, f)
return
}
}
func TestFilter_Set(t *testing.T) {
want := `(&(objectClass=employee)(cn=Jesse Coretta))`
f := Filter()
f.Set(want)
if want != f.String() {
t.Errorf("%T failed [SearchFilter.Set]:\nwant '%s'\ngot '%s'",
t.Name(), want, f)
return
}
}
func TestAttributeFilter(t *testing.T) {
var _afo AttributeFilter
_ = _afo.Parse(` ( hi ) `)
_, _, _ = parseAttrFilterOperPreamble(` ( hi )`)
afo := AF(AT(`cn`))
_ = afo.Valid()
_ = afo.IsZero()
_ = afo.AttributeType()
_ = afo.SearchFilter()
_ = afo.String()
afo = AF(Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`))
_ = afo.Valid()
_ = afo.IsZero()
_ = afo.AttributeType()
_ = afo.SearchFilter()
_ = afo.String()
var af AttributeFilter
_ = af.AttributeType()
_ = af.SearchFilter()
_ = af.String()
_ = af.Valid()
_ = af.IsZero()
want := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
af = AF(`objectClass`, `(&(objectClass=employee)(cn=Jesse Coretta))`)
if want != af.String() {
t.Errorf("%T failed [AttributeFilter]:\nwant '%s'\ngot '%s'",
t.Name(), want, af)
return
}
}
func TestAttributeFilterOperation_byStringParse(t *testing.T) {
straf := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
want := `add=` + straf
var afo AttributeFilterOperation
afo.Push()
_ = afo.Valid()
_ = afo.String()
_ = afo.Contains('𝝅')
_ = afo.Push('𝝅')
_ = afo.Push(nil)
_ = afo.Eq()
_ = afo.Pop()
_ = afo.Valid()
adder := AddOp.AFO(straf)
afo = AFO()
afo.Push()
_ = afo.String()
_ = afo.Valid()
_ = afo.Contains('𝝅')
_ = afo.Push('𝝅')
_ = afo.Push(nil)
_ = afo.Push(adder)
_ = afo.Push(adder.String())
_ = afo.Eq()
_ = afo.Pop()
_ = afo.Valid()
var af AttributeFilter
af.Parse(straf)
_ = hasAttributeFilterOperationPrefix(``)
_ = hasAttributeFilterOperationPrefix(af.String())
_ = afo.Contains(``)
_ = afo.Contains(af)
afo.Push(af)
_ = afo.Push(af.String())
if afo.String() != want {
t.Errorf("%T failed [AttributeFilterOperation.AFO]:\nwant '%s'\ngot '%s'",
t.Name(), want, afo)
return
}
}
func TestAttributeFilterOperation_byType(t *testing.T) {
at := AT(`objectClass`)
sf := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
afo := AF(at, sf)
want := `delete=` + at.String() + `:` + sf.String()
dafo := DelOp.AFO(afo)
if dafo.String() != want {
t.Errorf("%T failed [AttributeFilterOperation.AFO]:\nwant '%s'\ngot '%s'",
t.Name(), want, dafo)
return
}
}
func TestAttributeFilterOperation_addMultiVal(t *testing.T) {
af1 := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
af2 := `homeDirectory:(&(objectClass=accountant)(cn=Courtney Tolana))`
want := `add=` + af1 + ` && ` + af2
afo := AddOp.AFO(af1, af2)
if afo.String() != want {
t.Errorf("%T failed [AttributeFilterOperation.AFO(Add)]:\nwant '%s'\ngot '%s'",
t.Name(), want, afo)
return
}
af2a := afo.Pop()
if af2a.String() != af2 {
t.Errorf("%T failed [AttributeFilterOperation.Pop]:\nwant '%s'\ngot '%s'",
t.Name(), af2, af2a)
return
}
}
func TestAttributeFilterOperation_delMultiVal(t *testing.T) {
af1 := `nsroledn:(!(nsroledn=cn=X.500 Administrator))`
af2 := `telephoneNumber:(telephoneNumber=456*)`
want := `delete=` + af1 + ` && ` + af2
afo := DelOp.AFO(af1, af2)
if afo.String() != want {
t.Errorf("%T failed [AttributeFilterOperation.AFO(Delete)]:\nwant '%s'\ngot '%s'",
t.Name(), want, afo)
return
}
_ = afo.Contains(nil)
_ = afo.Contains(``)
_ = afo.pushPolicy()
_ = afo.pushPolicy(``)
_ = afo.pushPolicy(AddOp)
_ = afo.pushPolicy(nil, nil)
_ = afo.pushPolicy(nil)
_ = afo.pushPolicy(AF(``))
}
func TestAttributeFilterOperations_byStringParse(t *testing.T) {
badaf1 := `add==,objcectlcass*`
_, _ = parseAttributeFilterOperations(badaf1, 0)
af1 := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
af2 := `homeDirectory:(&(objectClass=accountant)(cn=Courtney Tolana))`
af3 := `nsroledn:(!(nsroledn=cn=X.500 Administrator))`
af4 := `telephoneNumber:(telephoneNumber=456*)`
want := `add=` + af1 + ` && ` + af2 + `,` + `delete=` + af3 + ` && ` + af4
// Parse the entirety of the want literal.
var afos AttributeFilterOperations
_ = afos.Contains('𝝅')
if err := afos.Parse(want); err != nil {
t.Errorf("%s failed [AttributeFilterOperations.Parse(raw)]: %v",
t.Name(), err)
return
}
_ = afos.Contains(nil)
_ = afos.pushPolicy()
_ = afos.pushPolicy(``)
_ = afos.pushPolicy(nil, nil)
_ = afos.pushPolicy(nil)
_ = afos.pushPolicy(AFO())
// verify the complete string representation
// matches that of the above want literal.
if afos.String() != want {
t.Errorf("%s failed [AttributeFilterOperations.Parse(compare)]:\nwant '%s'\ngot '%s'",
t.Name(), want, afos)
return
}
// verify the top-level stack's length.
if afos.Len() != 2 {
t.Errorf("%s failed [AttributeFilterOperations.Parse(chk AFOs len)]: want 'len:%d', got 'len:'%d'",
t.Name(), 2, afos.Len())
return
}
// scan the sub slices, verify those
// lengths as well.
for i := 0; i < 2; i++ {
if afo := afos.Index(i); afo.Len() != 2 {
t.Errorf("%s failed [AttributeFilterOperations.Parse(chk AFO len)]: want 'len:%d', got 'len:'%d'",
t.Name(), 2, afo.Len())
return
}
}
// try to fool the parser by specifying a semi delimiter, but w/o
// updating the above want string literal accordingly ...
if err := afos.Parse(want, AttributeFilterOperationsSemiDelim); err == nil {
t.Errorf("%s failed [AttributeFilterOperations.Parse(raw, alt delim)]: incorrect delimiter caused no error (but should have)",
t.Name())
return
}
}
func TestAttributeFilterOperations_byTypes(t *testing.T) {
af1 := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
af2 := `homeDirectory:(&(objectClass=accountant)(cn=Courtney Tolana))`
af3 := `nsroledn:(!(nsroledn=cn=X.500 Administrator))`
af4 := `telephoneNumber:(telephoneNumber=456*)`
afos := AFOs(
AddOp.AFO(af1, af2),
DelOp.AFO(af3, af4),
)
want1 := `add=` + af1 + ` && ` + af2
want2 := `delete=` + af3 + ` && ` + af4
want := want1 + `,` + want2
if afos.String() != want {
t.Errorf("%T failed [AttributeFilterOperations.AFOs]:\nwant '%s'\ngot '%s'",
t.Name(), want, afos)
return
}
af2a := afos.Pop()
if af2a.String() != want2 {
t.Errorf("%T failed [AttributeFilterOperations.Pop]:\nwant '%s'\ngot '%s'",
t.Name(), want2, af2a)
return
}
}
func TestAttributeFilterOperation_toTargetRule(t *testing.T) {
af := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
want := `( targattrfilters = "add=` + af + `" )`
rule := AddOp.AFO(af).Eq()
if rule.String() != want {
t.Errorf("%T failed [AttributeFilterOperation.Eq]:\nwant '%s'\ngot '%s'",
t.Name(), want, rule)
return
}
}
func TestAttributeFilterOperations_toTargetRule(t *testing.T) {
af1 := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
af2 := `homeDirectory:(&(objectClass=accountant)(cn=Courtney Tolana))`
af3 := `nsroledn:(!(nsroledn=cn=X.500 Administrator))`
af4 := `telephoneNumber:(telephoneNumber=456*)`
var afos AttributeFilterOperations
afos.Push()
_ = afos.Valid()
_ = afos.Eq()
var af AttributeFilter
var afo AttributeFilterOperation
_ = af.Parse(` lies `)
_ = afo.Parse(` lies `)
_ = afos.Parse(` lies `)
_ = af.IsZero()
_ = afo.IsZero()
_ = afos.IsZero()
_ = af.String()
_ = afo.String()
_ = afos.String()
// for codecov
if !afos.IsZero() {
t.Errorf("%s failed [%T.IsZero]:\nwant 'true'\ngot 'false'",
t.Name(), afos)
return
}
_ = afos.Contains('𝝅')
adder := AddOp.AFO(af1, af2)
deler := DelOp.AFO(af3, af4)
afos = AFOs(
adder,
deler,
)
_ = afos.Push('𝝅')
_ = afos.Push(nil)
_ = afos.Push(adder)
_ = afos.Push(adder.String())
_ = afos.Push('𝝅')
_ = afos.Push(``)
_ = afos.Push(nil)
_ = afos.Push(AddOp.AFO())
_ = afos.SetDelimiter(1)
_ = afos.SetDelimiter(0)
_ = afos.SetDelimiter()
_ = afos.Valid()
rule := afos.Eq()
want1 := `add=` + af1 + ` && ` + af2
want2 := `delete=` + af3 + ` && ` + af4
want := `( targattrfilters = "` + want1 + `,` + want2 + `" )`
if rule.String() != want {
t.Errorf("%T failed [AttributeFilterOperations.Eq]:\nwant '%s'\ngot '%s'",
t.Name(), want, rule)
return
}
}
/*
This example demonstrates the creation of an instance of [AttributeFilter], which
is strictly intended for use within instances of [AttributeFilterOperation].
In this example, proper type instances are fed to the package level [AF] function
to form a complete [AttributeFilter] instance.
The return type, [AttributeFilter], is then shown in string representation.
*/
func ExampleAF() {
af := AF(
AT(`homeDirectory`),
Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`),
)
fmt.Printf("%s", af)
// Output: homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))
}
/*
This example demonstrates the creation of an instance of AttributeFilter, which
is strictly intended for use within instances of [AttributeFilterOperation].
In this example, a raw string representation of an [AttributeFilter] is used for
parser input.
The return type, AttributeFilter, is then interrogated by way of the [AttributeFilter.AttributeType]
and [AttributeFilter.SearchFilter] methods it makes available to the user. An alternative to this
approach is to simply use its String method to get the whole value, if desired.
*/
func ExampleAttributeFilter_Parse() {
aftxt := `objectClass:(&(objectClass=employee)(cn=Jesse Coretta))`
var af AttributeFilter
_ = af.Parse(`4537895439h`)
err := af.Parse(aftxt)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("AT:%q, FILTER:%q", af.AttributeType(), af.SearchFilter())
// Output: AT:"objectClass", FILTER:"(&(objectClass=employee)(cn=Jesse Coretta))"
}
/*
This example demonstrates the creation of an instance of AttributeFilter, which
is strictly intended for use within instances of [AttributeFilterOperation].
In this example, proper type instances are fed to the Set method to form a
complete AttributeFilter instance.
The return type, AttributeFilter, is then shown in string representation.
*/
func ExampleAttributeFilter_Set() {
var af AttributeFilter // see also the package level AF function
af.Set(
AT(`homeDirectory`),
Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`),
)
fmt.Printf("%s", af)
// Output: homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))
}
/*
This example demonstrates the creation of an instance of AttributeFilter followed
by a call of its AttributeType method.
The return type, AttributeType, is shown in string representation.
*/
func ExampleAttributeFilter_AttributeType() {
aftxt := `homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))`
var af AttributeFilter
_ = af.Parse(aftxt) // shadow error for brevity
fmt.Printf("%s", af.AttributeType())
// Output: homeDirectory
}
/*
This example demonstrates the creation of an instance of AttributeFilter followed
by a call of its SearchFilter method.
The return type, SearchFilter, is shown in string representation.
*/
func ExampleAttributeFilter_SearchFilter() {
aftxt := `homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))`
var af AttributeFilter
_ = af.Parse(aftxt) // shadow error for brevity
fmt.Printf("%s", af.SearchFilter())
// Output: (&(objectClass=employee)(cn=Jesse Coretta))
}
/*
This example demonstrates a check of the receiver for "nilness".
*/
func ExampleAttributeFilter_IsZero() {
var af AttributeFilter
fmt.Printf("Is zero: %t (obviously)", af.IsZero())
// Output: Is zero: true (obviously)
}
/*
This example demonstrates the interrogation of the receiver in order to
discern the appropriate Keyword.
Its string representation, along with the name of the Keyword type, is
shown.
*/
func ExampleAttributeFilter_Keyword() {
var af AttributeFilter
fmt.Printf("Keyword is '%s' (type:%T)", af.Keyword(), af.Keyword())
// Output: Keyword is 'targattrfilters' (type:aci.TargetKeyword)
}
/*
This example demonstrates the creation of an instance of AttributeFilter followed
by a call of its String method.
The return value is the entirely of the receiver in string representation.
*/
func ExampleAttributeFilter_String() {
aftxt := `homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))`
var af AttributeFilter
_ = af.Parse(aftxt) // shadow error for brevity
fmt.Printf("%s", af)
// Output: homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))
}
/*
This example demonstrates the creation of an instance of AttributeFilter followed
by a call of its Valid method for the purpose of sanity checking the receiver.
An error is reported and printed to STDOUT.
*/
func ExampleAttributeFilter_Valid() {
var (
af AttributeFilter
err error
)
if err = af.Valid(); err != nil {
fmt.Println(err)
}
// Output: aci.AttributeFilter instance is nil
}
/*
This example demonstrates the creation of an instance of AttributeFilterOperation,
which is strictly intended for use within instances of [AttributeFilterOperations].
In this example, proper type instances are fed to the package level AFO function
to form a complete [AttributeFilterOperation] instance.
The return type, AttributeFilterOperation, is then shown in string representation.
*/
func ExampleAFO() {
// define the desired attributeType
attr := AT(`homeDirectory`)
// define the filter expression
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
// create an AttributeFilter instance
// using the above components
aF := AF(attr, filter)
// When using the package level AFO function, it
// is necessary to feed it an AttributeOperation
// instance (either AddOp or DelOp) to define the
// disposition of the new instance.
aFO := AFO(AddOp, aF)
fmt.Printf("%s", aFO)
// Output: add=homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))
}
/*
This example demonstrates an alternative to the AFO package level example. Instead
of feeding an instance of AttributeOperation into the function, one can also use
the AttributeOperation constant itself to generate the type instance needed. This
may be useful in situations which require portability of certain functionality.
*/
func ExampleAttributeFilterOperation_byAttributeOperationConstants() {
// define the desired attributeType
attr := AT(`homeDirectory`)
// define the filter expression
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
// create an AttributeFilter instance
// using the above components
aF := AF(attr, filter)
// We'll use the Delete operation (DelOp)
// package constant to spawn a new instance
// of AttributeFilterOperation. This will
// produce the same result as the AFO example
// demonstrated earlier, except this time we
// will impose the Delete operation.
aFO := DelOp.AFO(aF)
fmt.Printf("%s", aFO)
// Output: delete=homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Contains
method, allowing for basic text searches of the receiver.
Note that case is significant in the matching process for instances of this type.
*/
func ExampleAttributeFilterOperation_Contains() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO := AddOp.AFO(aF1, aF2)
fmt.Printf("%t", aFO.Contains(`homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))`))
// Output: true
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Eq method,
allowing for the creation of a TargetRule instance containing the receiver value,
and bearing the `targattrfilters` keyword context.
*/
func ExampleAttributeFilterOperation_Eq() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO := AddOp.AFO(aF1, aF2)
fmt.Printf("%s", aFO.Eq())
// Output: ( targattrfilters = "add=homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta)) && gecos:(|(objectClass=contractor)(objectClass=intern))" )
}
/*
This example demonstrates the use of the AttributeFilterOperation type's F method, which returns the appropriate slice building function for convenience.
*/
func ExampleAttributeFilterOperation_F() {
var aFO AttributeFilterOperation
// this returns the package-level AF function
Func := aFO.F()
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF := Func(attr, filter)
fmt.Printf("%s", aF)
// Output: homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta))
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Index method to allow iteration of the receiver's contents.
*/
func ExampleAttributeFilterOperation_Index() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO := AddOp.AFO(aF1, aF2)
idx := aFO.Index(1) // 2nd index in stack
fmt.Printf("%s", idx.AttributeType())
// Output: gecos
}
/*
This example demonstrates a check of the receiver for "nilness" using the AttributeFilterOperation type's IsZero method.
*/
func ExampleAttributeFilterOperation_IsZero() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF := AF(attr, filter)
aFO := AddOp.AFO(aF)
fmt.Printf("%t", aFO.IsZero())
// Output: false
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Len method to report the integer length of the receiver.
*/
func ExampleAttributeFilterOperation_Len() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO := AddOp.AFO(aF1, aF2)
fmt.Printf("Length: %d", aFO.Len())
// Output: Length: 2
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Keyword method.
*/
func ExampleAttributeFilterOperation_Keyword() {
var aFO AttributeFilterOperation
fmt.Printf("%s", aFO.Keyword())
// Output: targattrfilters
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Kind method.
*/
func ExampleAttributeFilterOperation_Kind() {
var aFO AttributeFilterOperation
fmt.Printf("%s", aFO.Kind())
// Output: targattrfilters
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Ne method,
which is not intended to be used in any situation ever. See the comments for this
method for details.
*/
func ExampleAttributeFilterOperation_Ne() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
af := AF(attr, filter)
aFO := AddOp.AFO(af)
bogus := aFO.Ne()
fmt.Printf("%t", bogus.IsZero())
// Output: true
}
/*
This example demonstrates a check of the receiver's operational disposition using the Operation method.
*/
func ExampleAttributeFilterOperation_Operation() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF := AF(attr, filter)
aFO := AddOp.AFO(aF)
fmt.Printf("%s", aFO.Operation())
// Output: add
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Pop method to remove the last stack slice per LIFO ordering.
*/
func ExampleAttributeFilterOperation_Pop() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO := AddOp.AFO(aF1, aF2)
popped := aFO.Pop()
fmt.Printf("%s", popped.AttributeType())
// Output: gecos
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Push method to append a new (eligible) instance to the receiver.
*/
func ExampleAttributeFilterOperation_Push() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
aFO := AddOp.AFO(aF1)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO.Push(aF2)
fmt.Printf("%s", aFO)
// Output: add=homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta)) && gecos:(|(objectClass=contractor)(objectClass=intern))
}
/*
This example demonstrates the creation of an instance of AttributeFilterOperation
followed by a call of its String method.
The return value is the entirely of the receiver in string representation.
*/
func ExampleAttributeFilterOperation_String() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO := AddOp.AFO(aF1, aF2)
fmt.Printf("%s", aFO)
// Output: add=homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta)) && gecos:(|(objectClass=contractor)(objectClass=intern))
}
/*
This example demonstrates the creation of an instance of AttributeFilterOperation
followed by a call of its Valid method for the purpose of sanity checking the receiver.
No error is reported and printed to STDOUT in this case, as the instance is valid.
*/
func ExampleAttributeFilterOperation_Valid() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF := AF(attr, filter)
aFO := AddOp.AFO(aF)
fmt.Printf("%t", aFO.Valid() == nil)
// Output: true
}
func ExampleAttributeFilterOperation_TRM() {
var afo AttributeFilterOperation
fmt.Printf("%d available aci.TargetRuleMethod instances", afo.TRM().Len())
// Output: 2 available aci.TargetRuleMethod instances
}
/*
This example demonstrates the creation of an instance of AttributeFilterOperations,
which is used to store individual AttributeFilterOperation instances.
In this example, proper type instances are fed to the package level AFOs function
to form a complete [AttributeFilterOperations] instance.
The return type, AttributeFilterOperations, is then shown in string representation.
*/
func ExampleAFOs() {
// define the desired attributeType
// and filter for the first element
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
// Create the AttributeFilterOperation
// instance (aFO)
aFO := AddOp.AFO(aF1, aF2)
// prepare our AttributeFilterOperations
// instance stack (aFOs) using the AFOs
// package level function.
aFOs := AFOs(aFO)
fmt.Printf("%s", aFOs)
// Output: add=homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta)) && gecos:(|(objectClass=contractor)(objectClass=intern))
}
/*
This example demonstrates the creation of an instance of AttributeFilterOperations,
which is used to store individual AttributeFilterOperation instances.
In this example, proper type instances are fed to the package level AFOs function
to form a complete [AttributeFilterOperations] instance.
The return type, AttributeFilterOperations, is then shown in string representation.
*/
func ExampleAttributeFilterOperations_Contains() {
// define the desired attributeType
// and filter for the first element
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
// Create the first AttributeFilterOperation
// instance (aFO1)
aFO1 := AddOp.AFO(aF1, aF2)
attr = AT(`uidNumber`)
filter = Filter(`(&(objectClass=accounting)(terminated=FALSE))`)
aF3 := AF(attr, filter)
attr = AT(`gidNumber`)
filter = Filter(`(objectClass=account)`)
aF4 := AF(attr, filter)
// Create the second AttributeFilterOperation
// instance (aFO2)
aFO2 := DelOp.AFO(aF3, aF4)
// prepare our AttributeFilterOperations
// instance stack (aFOs) using the AFOs
// package level function. Push both of
// the above AFO instances.
aFOs := AFOs(aFO1, aFO2)
fmt.Printf("%t", aFOs.Contains(`delete=uidNumber:(&(objectClass=accounting)(terminated=FALSE)) && gidNumber:(objectClass=account)`))
// Output: true
}
func ExampleAttributeFilterOperations_TRM() {
var afos AttributeFilterOperations
fmt.Printf("%d available aci.TargetRuleMethod instances", afos.TRM().Len())
// Output: 2 available aci.TargetRuleMethod instances
}
/*
This example demonstrates the use of the AttributeFilterOperations type's Eq method,
allowing for the creation of a TargetRule instance containing the receiver value,
and bearing the `targattrfilters` keyword context.
*/
func ExampleAttributeFilterOperations_Eq() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF1 := AF(attr, filter)
attr = AT(`gecos`)
filter = Filter(`(|(objectClass=contractor)(objectClass=intern))`)
aF2 := AF(attr, filter)
aFO := AddOp.AFO(aF1, aF2)
// all of the above was copied verbatim
// from the AttributeFilterOperation Eq
// example. All we're really doing here
// is enveloping it in another stack
aFOs := AFOs(aFO)
fmt.Printf("%s", aFOs.Eq())
// Output: ( targattrfilters = "add=homeDirectory:(&(objectClass=employee)(cn=Jesse Coretta)) && gecos:(|(objectClass=contractor)(objectClass=intern))" )
}
/*
This example demonstrates the use of the AttributeFilterOperation type's Ne method,
which is not intended to be used in any situation ever. See the comments for this
method for details.
*/
func ExampleAttributeFilterOperations_Ne() {
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
af := AF(attr, filter)
aFO := AddOp.AFO(af)
// all of the above was copied verbatim
// from the AttributeFilterOperation Ne
// example. All we're really doing here
// is enveloping it in another stack
aFOs := AFOs(aFO)
bogus := aFOs.Ne()
fmt.Printf("%t", bogus.IsZero())
// Output: true
}
/*
This example demonstrates the use of the AttributeFilterOperations type's F method, which returns the appropriate slice building function for convenience.
*/
func ExampleAttributeFilterOperations_F() {
var aFOs AttributeFilterOperations
// this returns the package-level AFO function
Func := aFOs.F()
attr := AT(`homeDirectory`)
filter := Filter(`(&(objectClass=employee)(cn=Jesse Coretta))`)
aF := Func(attr, filter)
aFO := Func(aF)
fmt.Printf("%T", aFO)
// Output: aci.AttributeFilterOperation
}
/*
This example demonstrates the use of the AttributeFilterOperations type's Index method to allow iteration of the receiver's contents.
*/
func ExampleAttributeFilterOperations_Index() {
// define the desired attributeType
// and filter for the first element