config: error if unknown filetype
This commit is contained in:
parent
04d88b0540
commit
aadb24aa08
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// configurable is an interface that must be implemented by any configuration
|
// configurable is an interface that must be implemented by any configuration
|
||||||
|
@ -30,7 +31,17 @@ type fileLoaderFunc func(path string) (configurable, []string, error)
|
||||||
// file. This function detects what kind of configuration file it is an
|
// file. This function detects what kind of configuration file it is an
|
||||||
// executes the proper fileLoaderFunc.
|
// executes the proper fileLoaderFunc.
|
||||||
func loadTree(root string) (*importTree, error) {
|
func loadTree(root string) (*importTree, error) {
|
||||||
c, imps, err := loadFileLibucl(root)
|
var f fileLoaderFunc
|
||||||
|
switch filepath.Ext(root) {
|
||||||
|
case ".tf":
|
||||||
|
f = loadFileLibucl
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"%s: uknown configuration format. Use '.tf' or '.tf.rb' extension",
|
||||||
|
root)
|
||||||
|
}
|
||||||
|
|
||||||
|
c, imps, err := f(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,13 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestLoad_badType(t *testing.T) {
|
||||||
|
_, err := Load(filepath.Join(fixtureDir, "bad_type.tf.nope"))
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should have error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadBasic(t *testing.T) {
|
func TestLoadBasic(t *testing.T) {
|
||||||
c, err := Load(filepath.Join(fixtureDir, "basic.tf"))
|
c, err := Load(filepath.Join(fixtureDir, "basic.tf"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
variable "foo" {}
|
Loading…
Reference in New Issue