11package base
22
33import (
4- "fmt"
54 "reflect"
65 "strconv"
76 "testing"
@@ -16,11 +15,10 @@ type StatPrepareSlotMock1 struct {
1615}
1716
1817func (spl * StatPrepareSlotMock1 ) Name () string {
19- return "mock-sentinel-prepare-slot1"
18+ return spl . name
2019}
2120
2221func (spl * StatPrepareSlotMock1 ) Prepare (ctx * EntryContext ) {
23- fmt .Println (spl .name )
2422 return
2523}
2624
@@ -72,11 +70,10 @@ type RuleCheckSlotMock1 struct {
7270}
7371
7472func (rcs * RuleCheckSlotMock1 ) Name () string {
75- return "mock-sentinel-rule-check-slot-1"
73+ return rcs . name
7674}
7775
7876func (rcs * RuleCheckSlotMock1 ) Check (ctx * EntryContext ) * TokenResult {
79- fmt .Println (rcs .name )
8077 return nil
8178}
8279func TestSlotChain_addRuleCheckSlotFirstAndLast (t * testing.T ) {
@@ -127,17 +124,17 @@ type StatSlotMock1 struct {
127124}
128125
129126func (ss * StatSlotMock1 ) Name () string {
130- return "mock-sentinel-stat-mock-slot-1"
127+ return ss . name
131128}
132129
133130func (ss * StatSlotMock1 ) OnEntryPassed (ctx * EntryContext ) {
134- fmt . Println ( ss . name )
131+ return
135132}
136133func (ss * StatSlotMock1 ) OnEntryBlocked (ctx * EntryContext , blockError * BlockError ) {
137- fmt . Printf ( "%s blocked: %v \n " , ss . name , blockError )
134+ return
138135}
139136func (ss * StatSlotMock1 ) OnCompleted (ctx * EntryContext ) {
140- fmt . Println ( ss . name )
137+ return
141138}
142139func TestSlotChain_addStatSlotFirstAndLast (t * testing.T ) {
143140 sc := NewSlotChain ()
@@ -387,3 +384,90 @@ func TestSlotChain_Entry_With_Panic(t *testing.T) {
387384 ssm .AssertNumberOfCalls (t , "OnEntryPassed" , 0 )
388385 ssm .AssertNumberOfCalls (t , "OnEntryBlocked" , 0 )
389386}
387+
388+ func TestValidateStatPrepareSlotNaming (t * testing.T ) {
389+ sc := NewSlotChain ()
390+ sps1 := & StatPrepareSlotMock1 {
391+ name : "sps1" ,
392+ }
393+ sps2 := & StatPrepareSlotMock1 {
394+ name : "sps2" ,
395+ }
396+ sps3 := & StatPrepareSlotMock1 {
397+ name : "sps3" ,
398+ }
399+ sps4 := & StatPrepareSlotMock1 {
400+ name : "sps4" ,
401+ }
402+ sc .AddStatPrepareSlotLast (sps1 )
403+ sc .AddStatPrepareSlotLast (sps2 )
404+ sc .AddStatPrepareSlotLast (sps3 )
405+ sc .AddStatPrepareSlotLast (sps4 )
406+
407+ sps5 := & StatPrepareSlotMock1 {
408+ name : "sps5" ,
409+ }
410+ assert .True (t , ValidateStatPrepareSlotNaming (sc , sps5 ))
411+ sps6 := & StatPrepareSlotMock1 {
412+ name : "sps1" ,
413+ }
414+ assert .True (t , ! ValidateStatPrepareSlotNaming (sc , sps6 ))
415+ }
416+
417+ func TestValidateRuleCheckSlotNaming (t * testing.T ) {
418+ sc := NewSlotChain ()
419+ rcs1 := & RuleCheckSlotMock1 {
420+ name : "rcs1" ,
421+ }
422+ rcs2 := & RuleCheckSlotMock1 {
423+ name : "rcs2" ,
424+ }
425+ rcs3 := & RuleCheckSlotMock1 {
426+ name : "rcs3" ,
427+ }
428+ rcs4 := & RuleCheckSlotMock1 {
429+ name : "rcs4" ,
430+ }
431+ sc .AddRuleCheckSlotLast (rcs1 )
432+ sc .AddRuleCheckSlotLast (rcs2 )
433+ sc .AddRuleCheckSlotLast (rcs3 )
434+ sc .AddRuleCheckSlotLast (rcs4 )
435+
436+ rcs5 := & RuleCheckSlotMock1 {
437+ name : "rcs5" ,
438+ }
439+ assert .True (t , ValidateRuleCheckSlotNaming (sc , rcs5 ))
440+ rcs6 := & RuleCheckSlotMock1 {
441+ name : "rcs1" ,
442+ }
443+ assert .True (t , ! ValidateRuleCheckSlotNaming (sc , rcs6 ))
444+ }
445+
446+ func TestValidateStatSlotNaming (t * testing.T ) {
447+ sc := NewSlotChain ()
448+ ss1 := & StatSlotMock1 {
449+ name : "ss1" ,
450+ }
451+ ss2 := & StatSlotMock1 {
452+ name : "ss2" ,
453+ }
454+ ss3 := & StatSlotMock1 {
455+ name : "ss3" ,
456+ }
457+ ss4 := & StatSlotMock1 {
458+ name : "ss4" ,
459+ }
460+ sc .AddStatSlotLast (ss1 )
461+ sc .AddStatSlotLast (ss2 )
462+ sc .AddStatSlotLast (ss3 )
463+ sc .AddStatSlotLast (ss4 )
464+
465+ ss5 := & StatSlotMock1 {
466+ name : "ss5" ,
467+ }
468+ assert .True (t , ValidateStatSlotNaming (sc , ss5 ))
469+ ss6 := & StatSlotMock1 {
470+ name : "ss1" ,
471+ }
472+ assert .True (t , ! ValidateStatSlotNaming (sc , ss6 ))
473+ }
0 commit comments