From 7633354ca48a858cacf0e613e870972c5958f877 Mon Sep 17 00:00:00 2001 From: Ben Drucker Date: Thu, 6 Jul 2023 09:21:54 -0700 Subject: [PATCH] Un-export `NewLocalRunner` and `AddLocalFile` --- helper/runner.go | 13 +++++++------ helper/testing.go | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/helper/runner.go b/helper/runner.go index e910840..10118a4 100644 --- a/helper/runner.go +++ b/helper/runner.go @@ -350,9 +350,8 @@ func (r *Runner) EnsureNoError(err error, proc func() error) error { return err } -// NewLocalRunner initialises a new test runner. -// Internal use only. -func NewLocalRunner(files map[string]*hcl.File, issues Issues) *Runner { +// newLocalRunner initialises a new test runner. +func newLocalRunner(files map[string]*hcl.File, issues Issues) *Runner { return &Runner{ files: map[string]*hcl.File{}, sources: map[string][]byte{}, @@ -361,9 +360,9 @@ func NewLocalRunner(files map[string]*hcl.File, issues Issues) *Runner { } } -// AddLocalFile adds a new file to the current mapped files. -// Internal use only. -func (r *Runner) AddLocalFile(name string, file *hcl.File) bool { +// addLocalFile adds a new file to the current mapped files. +// For testing only. Normally, the main TFLint process is responsible for loading files. +func (r *Runner) addLocalFile(name string, file *hcl.File) bool { if _, exists := r.files[name]; exists { return false } @@ -373,6 +372,8 @@ func (r *Runner) AddLocalFile(name string, file *hcl.File) bool { return true } +// initFromFiles initializes the runner from locally added files. +// For testing only. func (r *Runner) initFromFiles() error { for _, file := range r.files { content, _, diags := file.Body.PartialContent(configFileSchema) diff --git a/helper/testing.go b/helper/testing.go index 04b313d..c7d723c 100644 --- a/helper/testing.go +++ b/helper/testing.go @@ -19,7 +19,7 @@ import ( func TestRunner(t *testing.T, files map[string]string) *Runner { t.Helper() - runner := NewLocalRunner(map[string]*hcl.File{}, Issues{}) + runner := newLocalRunner(map[string]*hcl.File{}, Issues{}) parser := hclparse.NewParser() for name, src := range files { @@ -41,7 +41,7 @@ func TestRunner(t *testing.T, files map[string]string) *Runner { } runner.config = config } else { - runner.AddLocalFile(name, file) + runner.addLocalFile(name, file) } }