Skip to content

Add Keys helper. Switch to Dep. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/fatih/color"
version = "1.5.0"

[[constraint]]
branch = "master"
name = "github.com/go-errors/errors"

[[constraint]]
branch = "master"
name = "github.com/mattn/go-zglob"

[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.3"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.1.4"

[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ This package contains two types of helpers:
## Running tests

```
go test -v $(glide novendor)
go test -v ./...
```
12 changes: 4 additions & 8 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
machine:
environment:
PATH: $PATH:$HOME/glide/linux-amd64

dependencies:
override:
# Install the gruntwork-module-circleci-helpers and use it to configure the build environment and run tests.
- curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version v0.0.16
- gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.3.17"
- configure-environment-for-gruntwork-module --terraform-version NONE --packer-version NONE --terragrunt-version NONE --go-src-path .
- curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version v0.0.20
- gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.4.0"
- configure-environment-for-gruntwork-module --terraform-version NONE --packer-version NONE --terragrunt-version NONE --go-src-path . --use-go-dep

cache_directories:
- ~/glide
- ~/dep

test:
override:
Expand Down
14 changes: 14 additions & 0 deletions collections/maps.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package collections

import "sort"

// Merge all the maps into one. Sadly, Go has no generics, so this is only defined for string to interface maps.
func MergeMaps(maps ... map[string]interface{}) map[string]interface{} {
out := map[string]interface{}{}
Expand All @@ -13,3 +15,15 @@ func MergeMaps(maps ... map[string]interface{}) map[string]interface{} {
return out
}

// Return the keys for the given map, sorted alphabetically
func Keys(m map[string]string) []string {
out := []string{}

for key, _ := range m {
out = append(out, key)
}

sort.Strings(out)

return out
}
21 changes: 21 additions & 0 deletions collections/maps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package collections
import (
"testing"
"github.com/stretchr/testify/assert"
"fmt"
)

func TestMergeMapsNoMaps(t *testing.T) {
Expand Down Expand Up @@ -117,3 +118,23 @@ func TestMergeMapsMultipleNonEmptyMapsOverlappingKeys(t *testing.T) {

assert.Equal(t, expected, MergeMaps(map1, map2, map3))
}

func TestKeys(t *testing.T) {
t.Parallel()

testCases := []struct {
input map[string]string
expected []string
}{
{map[string]string{}, []string{}},
{map[string]string{"a": "foo"}, []string{"a"}},
{map[string]string{"a": "foo", "b": "bar", "c": "baz"}, []string{"a", "b", "c"}},
}

for _, testCase := range testCases {
t.Run(fmt.Sprintf("%v", testCase.input), func(t *testing.T) {
actual := Keys(testCase.input)
assert.Equal(t, testCase.expected, actual)
})
}
}
26 changes: 0 additions & 26 deletions glide.lock

This file was deleted.

13 changes: 0 additions & 13 deletions glide.yaml

This file was deleted.