Skip to content

Commit

Permalink
Add integration tests for BoldDB & fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
stuart-c committed Aug 2, 2017
1 parent 4c7f422 commit 2a10416
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
11 changes: 9 additions & 2 deletions data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -104,7 +105,7 @@ func NewSource(alias string, URL *url.URL) (s *Source) {
Ext: ext,
}

if ext != "" {
if ext != "" && URL.Scheme != "boltdb" {
mediatype := mime.TypeByExtension(ext)
t, params, err := mime.ParseMediaType(mediatype)
if err != nil {
Expand Down Expand Up @@ -346,7 +347,13 @@ func readLibKV(source *Source, args ...string) ([]byte, error) {
}

p := source.URL.Path
if len(args) == 1 {

if source.URL.Scheme == "boltdb" {
if len(args) != 1 {
return nil, errors.New("missing key")
}
p = args[0]
} else if len(args) == 1 {
p = p + "/" + args[0]
}

Expand Down
1 change: 1 addition & 0 deletions test/integration/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ COPY mirror /bin/mirror
COPY *.sh /tests/
COPY *.bash /tests/
COPY *.bats /tests/
COPY *.db /test/integration/

CMD ["/tests/test.sh"]
Binary file added test/integration/config.db
Binary file not shown.
27 changes: 27 additions & 0 deletions test/integration/datasources_boltdb.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bats

load helper

tmpdir=$(mktemp -u)

function setup () {
mkdir -p $tmpdir
}

function teardown () {
rm -rf $tmpdir || true
}

@test "supports BoltDB datasource file" {
cp test/integration/config.db $tmpdir/config.db
gomplate -d config=boltdb://$tmpdir/config.db#Bucket1 -i '{{(datasource "config" "foo")}}'
[ "$status" -eq 0 ]
[[ "${output}" == "bar" ]]
}

@test "supports multi-bucket BoltDB datasource file" {
cp test/integration/config.db $tmpdir/config.db
gomplate -d config=boltdb://$tmpdir/config.db#Bucket1 -d config2=boltdb://$tmpdir/config.db#Bucket2 -i '{{(datasource "config" "foo")}}-{{(datasource "config2" "foobar")}}'
[ "$status" -eq 0 ]
[[ "${output}" == "bar-baz" ]]
}

0 comments on commit 2a10416

Please sign in to comment.