diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 8c0734d..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,319 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:b16fbfbcc20645cb419f78325bb2e85ec729b338e996a228124d68931a6f2a37" - name = "github.com/BurntSushi/toml" - packages = ["."] - pruneopts = "UT" - revision = "b26d9c308763d68093482582cea63d69be07a0f0" - version = "v0.3.0" - -[[projects]] - digest = "1:9b795384333e3d34668689120fcaa583cc54c2e06ef995fbb174c133349b577c" - name = "github.com/coreos/etcd" - packages = [ - "auth/authpb", - "clientv3", - "etcdserver/api/v3rpc/rpctypes", - "etcdserver/etcdserverpb", - "mvcc/mvccpb", - "pkg/types", - ] - pruneopts = "UT" - revision = "e348b1aedd9167360c466ae98f7343d3e22281f8" - version = "v3.3.3" - -[[projects]] - digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" - name = "github.com/davecgh/go-spew" - packages = ["spew"] - pruneopts = "UT" - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - -[[projects]] - digest = "1:ca82a3b99694824c627573c2a76d0e49719b4a9c02d1d85a2ac91f1c1f52ab9b" - name = "github.com/fatih/structs" - packages = ["."] - pruneopts = "UT" - revision = "a720dfa8df582c51dee1b36feabb906bde1588bd" - version = "v1.0" - -[[projects]] - digest = "1:8f13f978d35181fada0ea713c14a224f2b329fa91c13438b2811331ecd8b16e1" - name = "github.com/gogo/protobuf" - packages = [ - "gogoproto", - "proto", - "protoc-gen-gogo/descriptor", - ] - pruneopts = "UT" - revision = "1adfc126b41513cc696b209667c8656ea7aac67c" - version = "v1.0.0" - -[[projects]] - digest = "1:8caffcd8995b0eae7d2c18b2baefabef331bb05b1e16ed2b26b732c3349e6989" - name = "github.com/golang/protobuf" - packages = [ - "proto", - "ptypes", - "ptypes/any", - "ptypes/duration", - "ptypes/timestamp", - ] - pruneopts = "UT" - revision = "925541529c1fa6821df4e44ce2723319eb2be768" - version = "v1.0.0" - -[[projects]] - branch = "master" - digest = "1:29a5ab9fa9e845fd8e8726f31b187d710afd271ef1eb32085fe3d604b7e06382" - name = "github.com/golang/snappy" - packages = ["."] - pruneopts = "UT" - revision = "553a641470496b2327abcac10b36396bd98e45c9" - -[[projects]] - digest = "1:7d9085638f210faa86720b5fe8c4cd9303edb853ed93929852a4384a4e6c956f" - name = "github.com/hashicorp/consul" - packages = ["api"] - pruneopts = "UT" - revision = "fb848fc48818f58690db09d14640513aa6bf3c02" - version = "v1.0.7" - -[[projects]] - branch = "master" - digest = "1:07671f8997086ed115824d1974507d2b147d1e0463675ea5dbf3be89b1c2c563" - name = "github.com/hashicorp/errwrap" - packages = ["."] - pruneopts = "UT" - revision = "7554cd9344cec97297fa6649b055a8c98c2a1e55" - -[[projects]] - branch = "master" - digest = "1:77cb3be9b21ba7f1a4701e870c84ea8b66e7d74c7c8951c58155fdadae9414ec" - name = "github.com/hashicorp/go-cleanhttp" - packages = ["."] - pruneopts = "UT" - revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d" - -[[projects]] - branch = "master" - digest = "1:e5048c5da80697be2fcdecc944e29d2999e01fd7f48b643168443209779f3463" - name = "github.com/hashicorp/go-multierror" - packages = ["."] - pruneopts = "UT" - revision = "b7773ae218740a7be65057fc60b366a49b538a44" - -[[projects]] - branch = "master" - digest = "1:45aad874d3c7d5e8610427c81870fb54970b981692930ec2a319ce4cb89d7a00" - name = "github.com/hashicorp/go-rootcerts" - packages = ["."] - pruneopts = "UT" - revision = "6bb64b370b90e7ef1fa532be9e591a81c3493e00" - -[[projects]] - branch = "master" - digest = "1:12247a2e99a060cc692f6680e5272c8adf0b8f572e6bce0d7095e624c958a240" - name = "github.com/hashicorp/hcl" - packages = [ - ".", - "hcl/ast", - "hcl/parser", - "hcl/scanner", - "hcl/strconv", - "hcl/token", - "json/parser", - "json/scanner", - "json/token", - ] - pruneopts = "UT" - revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168" - -[[projects]] - digest = "1:0dd7b7b01769f9df356dc99f9e4144bdbabf6c79041ea7c0892379c5737f3c44" - name = "github.com/hashicorp/serf" - packages = ["coordinate"] - pruneopts = "UT" - revision = "d6574a5bb1226678d7010325fb6c985db20ee458" - version = "v0.8.1" - -[[projects]] - digest = "1:62acb0602e1fa54327d91ca4290e286b47216f316f1c35fa400a493a0e92af94" - name = "github.com/hashicorp/vault" - packages = [ - "api", - "helper/compressutil", - "helper/jsonutil", - "helper/parseutil", - "helper/strutil", - ] - pruneopts = "UT" - revision = "7e1fbde40afee241f81ef08700e7987d86fc7242" - version = "v0.9.6" - -[[projects]] - branch = "master" - digest = "1:12ae6210bdbdad658a9a67fd95cd9c99f7fdbf12f6d36eaf0af704e69dacf4f5" - name = "github.com/mitchellh/go-homedir" - packages = ["."] - pruneopts = "UT" - revision = "b8bc1bf767474819792c23f32d8286a45736f1c6" - -[[projects]] - branch = "master" - digest = "1:2514da1e59c0a936d8c1e0fbf5592267a3c5893eb4555ce767bb54d149e9cf6e" - name = "github.com/mitchellh/mapstructure" - packages = ["."] - pruneopts = "UT" - revision = "00c29f56e2386353d58c599509e8dc3801b0d716" - -[[projects]] - digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" - name = "github.com/pkg/errors" - packages = ["."] - pruneopts = "UT" - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" - -[[projects]] - digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - pruneopts = "UT" - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - digest = "1:0e792eea6c96ec55ff302ef33886acbaa5006e900fefe82689e88d96439dcd84" - name = "github.com/ryanuber/go-glob" - packages = ["."] - pruneopts = "UT" - revision = "572520ed46dbddaed19ea3d9541bdd0494163693" - version = "v0.1" - -[[projects]] - branch = "master" - digest = "1:ed1ce33d4bca1c70e0d596f528ecebcfaac8f745003b651a8e73121d1e4189e0" - name = "github.com/sethgrid/pester" - packages = ["."] - pruneopts = "UT" - revision = "ed9870dad3170c0b25ab9b11830cc57c3a7798fb" - -[[projects]] - digest = "1:7e8d267900c7fa7f35129a2a37596e38ed0f11ca746d6d9ba727980ee138f9f6" - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require", - ] - pruneopts = "UT" - revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" - version = "v1.2.1" - -[[projects]] - branch = "master" - digest = "1:01ec943e74da037584f3abd30f6007766458e21e48a2d7a99a4627e0ce3f198f" - name = "golang.org/x/net" - packages = [ - "context", - "http/httpguts", - "http2", - "http2/hpack", - "idna", - "internal/timeseries", - "lex/httplex", - "trace", - ] - pruneopts = "UT" - revision = "d41e8174641f662c5a2d1c7a5f9e828788eb8706" - -[[projects]] - digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" - name = "golang.org/x/text" - packages = [ - "collate", - "collate/build", - "internal/colltab", - "internal/gen", - "internal/tag", - "internal/triegen", - "internal/ucd", - "language", - "secure/bidirule", - "transform", - "unicode/bidi", - "unicode/cldr", - "unicode/norm", - "unicode/rangetable", - ] - pruneopts = "UT" - revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" - version = "v0.3.0" - -[[projects]] - branch = "master" - digest = "1:cd018653a358d4b743a9d3bee89e825521f2ab2f2ec0770164bf7632d8d73ab7" - name = "google.golang.org/genproto" - packages = ["googleapis/rpc/status"] - pruneopts = "UT" - revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200" - -[[projects]] - digest = "1:bbd9219ca27e0bc3a8d98bb599dff0eab24f39a8c9e519e6faa5b9a17598cc8d" - name = "google.golang.org/grpc" - packages = [ - ".", - "balancer", - "balancer/base", - "balancer/roundrobin", - "codes", - "connectivity", - "credentials", - "encoding", - "encoding/proto", - "grpclb/grpc_lb_v1/messages", - "grpclog", - "health/grpc_health_v1", - "internal", - "keepalive", - "metadata", - "naming", - "peer", - "resolver", - "resolver/dns", - "resolver/passthrough", - "stats", - "status", - "tap", - "transport", - ] - pruneopts = "UT" - revision = "d11072e7ca9811b1100b80ca0269ac831f06d024" - version = "v1.11.3" - -[[projects]] - digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "UT" - revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" - version = "v2.2.1" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/BurntSushi/toml", - "github.com/coreos/etcd/clientv3", - "github.com/hashicorp/consul/api", - "github.com/hashicorp/vault/api", - "github.com/pkg/errors", - "github.com/stretchr/testify/assert", - "github.com/stretchr/testify/require", - "gopkg.in/yaml.v2", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 1938f6e..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,31 +0,0 @@ -[[constraint]] - name = "github.com/coreos/etcd" - version = "3.0.0" - -[[constraint]] - name = "gopkg.in/yaml.v2" - version = "2.2.1" - -[[constraint]] - name = "github.com/hashicorp/consul" - version = "1.0.0" - -[[constraint]] - name = "github.com/pkg/errors" - version = "0.8.0" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.1.4" - -[[constraint]] - name = "github.com/hashicorp/vault" - version = "0.9.0" - -[prune] - go-tests = true - unused-packages = true - -[[constraint]] - name = "github.com/BurntSushi/toml" - version = "0.3.0" diff --git a/backend/file/file_test.go b/backend/file/file_test.go index 9ad8b7f..859bfc8 100644 --- a/backend/file/file_test.go +++ b/backend/file/file_test.go @@ -40,15 +40,18 @@ func TestFileBackend(t *testing.T) { Timeout time.Duration } - testLoad := func(t *testing.T, path string) { - var c config + ekv := config{ + Name: "some name", + Age: 10, + Timeout: 10, + } + + testLoad := func(t *testing.T, path string, template interface{}, expected interface{}) { b := file.NewBackend(path) - err := b.Unmarshal(context.Background(), &c) + err := b.Unmarshal(context.Background(), template) require.NoError(t, err) - require.Equal(t, "some name", c.Name) - require.Equal(t, 10, c.Age) - require.Equal(t, 10*time.Nanosecond, c.Timeout) + require.EqualValues(t, expected, template) } t.Run("JSON", func(t *testing.T) { @@ -59,7 +62,7 @@ func TestFileBackend(t *testing.T) { }`) defer cleanup() - testLoad(t, path) + testLoad(t, path, &config{}, &ekv) }) t.Run("YAML", func(t *testing.T) { @@ -70,18 +73,66 @@ func TestFileBackend(t *testing.T) { `) defer cleanup() - testLoad(t, path) + testLoad(t, path, &config{}, &ekv) }) - t.Run("TOML", func(t *testing.T) { - path, cleanup := createTempFile(t, "config.toml", - `name = "some name" + + t.Run("Simple KV", func(t *testing.T) { + path, cleanup := createTempFile(t, "config.toml", + `name = "some name" age = 10 timeout = 10 `) - defer cleanup() + defer cleanup() + + testLoad(t, path, &config{}, &ekv) + }) + + t.Run("TOML Table", func(t *testing.T) { + path, cleanup := createTempFile(t, "config.toml", + `title = "title!" +[Config] +name = "some name" +age = 10 +timeout = 10 +`) + defer cleanup() + type Config struct { + Title string + Config config + } + e := Config{ + Title: "title!", + Config: config{ + Name: "some name", + Age: 10, + Timeout: 10, + }, + } + + testLoad(t, path, &Config{}, &e) + }) + + t.Run("TOML Array of Tables", func(t *testing.T) { + path, cleanup := createTempFile(t, "config.toml", + `[[Config]] +name = "Alice" +age = 10 +timeout = 10 +[[Config]] +name = "Bob" +age = 11 +timeout = 11 +`) + defer cleanup() + type Configs struct { + Config []config + } + e := Configs{Config: []config{{Name: "Alice", Age: 10, Timeout: 10}, {Name: "Bob", Age: 11, Timeout: 11}}} + + testLoad(t, path, &Configs{}, &e) + }) - testLoad(t, path) }) t.Run("Unsupported extension", func(t *testing.T) {