Skip to content

Commit

Permalink
Merge pull request #2 from deepthawtz/dylan/fix_prefix_bug
Browse files Browse the repository at this point in the history
fix prefix bug
  • Loading branch information
deepthawtz authored Aug 21, 2016
2 parents 399b8b0 + 8f08dd7 commit c0a30ed
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd
import (
"fmt"
"os"
"strings"
"path"
"sync"

"github.com/deepthawtz/kv/store"
Expand Down Expand Up @@ -58,7 +58,7 @@ func del(client *consul.KV, args ...string) error {
for _, k := range args {
wg.Add(1)
go func(k string) {
key := strings.Join([]string{prefix, k}, "/")
key := path.Join(prefix, k)
_, err := client.Delete(key, nil)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/del_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"strings"
"path"
"testing"

consul "github.com/hashicorp/consul/api"
Expand All @@ -13,7 +13,7 @@ func TestDel(t *testing.T) {
kv := c.KV()

prefix = "env/yo/stage"
k := strings.Join([]string{prefix, "YO"}, "/")
k := path.Join(prefix, "YO")
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("123")}, nil)

if err := del(kv, []string{"YO"}...); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"fmt"
"os"
"path"
"regexp"
"strings"

Expand Down Expand Up @@ -136,7 +137,7 @@ func matchingKVPairs(scoped consul.KVPairs, args []string) (consul.KVPairs, erro

for _, s := range specific {
for _, k := range scoped {
key := strings.Join([]string{prefix, s}, "/")
key := path.Join(prefix, s)
if key == string(k.Key) {
kvpairs = append(kvpairs, k)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/get_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"strings"
"path"
"testing"

consul "github.com/hashicorp/consul/api"
Expand Down Expand Up @@ -40,11 +40,11 @@ func TestGet(t *testing.T) {
kv := c.KV()

prefix = "env/yo/stage"
k := strings.Join([]string{prefix, "YO"}, "/")
k := path.Join(prefix, "YO")
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("123")}, nil)
k = strings.Join([]string{prefix, "THING_ID"}, "/")
k = path.Join(prefix, "THING_ID")
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("abc123")}, nil)
k = strings.Join([]string{prefix, "THING_TOKEN"}, "/")
k = path.Join(prefix, "THING_TOKEN")
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("yabbadabba")}, nil)

cases := []struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"fmt"
"os"
"path"
"strings"
"sync"

Expand Down Expand Up @@ -73,7 +74,7 @@ func set(client *consul.KV, args ...string) error {

wg.Add(1)
go func() {
k := strings.Join([]string{prefix, parts[0]}, "/")
k := path.Join(prefix, parts[0])
v := parts[1]
fmt.Printf("setting %s = %s\n", k, v)
if _, err := client.Put(&consul.KVPair{Key: k, Value: []byte(v)}, nil); err != nil {
Expand Down

0 comments on commit c0a30ed

Please sign in to comment.