@@ -41,6 +41,7 @@ type mockRuleSetImpl struct {
41
41
configSchema func () * hclext.BodySchema
42
42
applyGlobalConfig func (* tflint.Config ) error
43
43
applyConfig func (* hclext.BodyContent ) error
44
+ newRunner func (tflint.Runner ) (tflint.Runner , error )
44
45
check func (tflint.Runner ) error
45
46
}
46
47
@@ -79,6 +80,13 @@ func (r *mockRuleSet) ApplyConfig(content *hclext.BodyContent) error {
79
80
return nil
80
81
}
81
82
83
+ func (r * mockRuleSet ) NewRunner (runner tflint.Runner ) (tflint.Runner , error ) {
84
+ if r .impl .newRunner != nil {
85
+ return r .impl .newRunner (runner )
86
+ }
87
+ return runner , nil
88
+ }
89
+
82
90
func (r * mockRuleSet ) Check (runner tflint.Runner ) error {
83
91
if r .impl .check != nil {
84
92
return r .impl .check (runner )
@@ -575,6 +583,14 @@ func (s *mockServer) GetFiles(tflint.ModuleCtxType) map[string][]byte {
575
583
return map [string ][]byte {}
576
584
}
577
585
586
+ type mockCustomRunner struct {
587
+ tflint.Runner
588
+ }
589
+
590
+ func (s * mockCustomRunner ) Hello () string {
591
+ return "Hello from custom runner!"
592
+ }
593
+
578
594
func TestCheck (t * testing.T ) {
579
595
// default error check helper
580
596
neverHappend := func (err error ) bool { return err != nil }
@@ -589,10 +605,11 @@ func TestCheck(t *testing.T) {
589
605
}
590
606
591
607
tests := []struct {
592
- Name string
593
- Arg func () plugin2host.Server
594
- ServerImpl func (tflint.Runner ) error
595
- ErrCheck func (error ) bool
608
+ Name string
609
+ Arg func () plugin2host.Server
610
+ ServerImpl func (tflint.Runner ) error
611
+ NewRunnerImpl func (tflint.Runner ) (tflint.Runner , error )
612
+ ErrCheck func (error ) bool
596
613
}{
597
614
{
598
615
Name : "bidirectional" ,
@@ -667,11 +684,26 @@ resource "aws_instance" "foo" {
667
684
return err == nil || err .Error () != "unexpected error"
668
685
},
669
686
},
687
+ {
688
+ Name : "inject new runner" ,
689
+ Arg : func () plugin2host.Server {
690
+ return & mockServer {}
691
+ },
692
+ NewRunnerImpl : func (runner tflint.Runner ) (tflint.Runner , error ) {
693
+ return & mockCustomRunner {runner }, nil
694
+ },
695
+ ServerImpl : func (runner tflint.Runner ) error {
696
+ return errors .New (runner .(* mockCustomRunner ).Hello ())
697
+ },
698
+ ErrCheck : func (err error ) bool {
699
+ return err == nil || err .Error () != "Hello from custom runner!"
700
+ },
701
+ },
670
702
}
671
703
672
704
for _ , test := range tests {
673
705
t .Run (test .Name , func (t * testing.T ) {
674
- client := startTestGRPCPluginServer (t , newMockRuleSet ("test_ruleset" , "0.1.0" , mockRuleSetImpl {check : test .ServerImpl }))
706
+ client := startTestGRPCPluginServer (t , newMockRuleSet ("test_ruleset" , "0.1.0" , mockRuleSetImpl {check : test .ServerImpl , newRunner : test . NewRunnerImpl }))
675
707
676
708
err := client .Check (test .Arg ())
677
709
if test .ErrCheck (err ) {
0 commit comments