From dd62cd97c9eae8f66ce4bc9b0416be95558fcb24 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 6 Apr 2018 18:46:13 -0700 Subject: [PATCH] configs: DisabledModuleWalker This is a built-in implementation of ModuleWalker that just returns an error any time it's asked for a module. This is intended for simple unit tests where no child modules are needed anyway. --- configs/config_build.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/configs/config_build.go b/configs/config_build.go index b33d121e4..8f7fa6b16 100644 --- a/configs/config_build.go +++ b/configs/config_build.go @@ -156,3 +156,23 @@ type ModuleRequest struct { // rather than to either its source address or its version number. CallRange hcl.Range } + +// DisabledModuleWalker is a ModuleWalker that doesn't support +// child modules at all, and so will return an error if asked to load one. +// +// This is provided primarily for testing. There is no good reason to use this +// in the main application. +var DisabledModuleWalker ModuleWalker + +func init() { + DisabledModuleWalker = ModuleWalkerFunc(func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics) { + return nil, nil, hcl.Diagnostics{ + { + Severity: hcl.DiagError, + Summary: "Child modules are not supported", + Detail: "Child module calls are not allowed in this context.", + Subject: &req.CallRange, + }, + } + }) +}