Skip to content

Commit

Permalink
add ability to compare envs
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonmbanks committed Jan 26, 2017
1 parent 0ee8bdd commit b4982ee
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ import (

func extractKeys(fileData []byte, ymlPathArgs []string) []string {
keys := make([]string, 0, 50)
y, _ := simpleyaml.NewYaml(fileData)
data, _ := y.GetPath(ymlPathArgs...).String()
data := ""
if len(ymlPathArgs) > 0 {
y, _ := simpleyaml.NewYaml(fileData)
data, _ = y.GetPath(ymlPathArgs...).String()
} else {
data = string(fileData[:])
}
lines := strings.Split(data, "\n")
for _, line := range lines {
keyVals := strings.Split(line, "=")
Expand Down Expand Up @@ -81,7 +86,11 @@ func main() {

app.Action = func(c *cli.Context) error {
fileNames := strings.Split(c.Args().Get(0), ",")
ymlArgs := strings.Split(c.Args().Get(1), ",")
ymlArgs := []string{}
cmdArgs := c.Args().Get(1)
if cmdArgs != "" {
ymlArgs = strings.Split(c.Args().Get(1), ",")
}
envKeys := ParseFileData(fileNames, ymlArgs)
result := CompareEnvArrays(envKeys, fileNames)
if result {
Expand Down
24 changes: 22 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import "testing"
import (
"testing"

import "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)

func TestParseData(t *testing.T) {
fileNames := []string{"testfiles/data1.yml", "testfiles/data2.yml"}
Expand Down Expand Up @@ -64,3 +66,21 @@ func TestComparingArraysThatArentEqualByLength(t *testing.T) {
testArraysAreEqual := CompareEnvArrays(expectedValues, fileNames)
assert.Equal(t, false, testArraysAreEqual)
}

func TestComparingEnvFilesThatAreEqual(t *testing.T) {
fileNames := []string{"testfiles/.env1", "testfiles/.env2"}

ymlArgs := []string{}
envKeys := ParseFileData(fileNames, ymlArgs)
result := CompareEnvArrays(envKeys, fileNames)
assert.Equal(t, true, result)
}

func TestComparingEnvFilesThatAreNotEqual(t *testing.T) {
fileNames := []string{"testfiles/.env1", "testfiles/.env3"}

ymlArgs := []string{}
envKeys := ParseFileData(fileNames, ymlArgs)
result := CompareEnvArrays(envKeys, fileNames)
assert.Equal(t, false, result)
}
2 changes: 2 additions & 0 deletions testfiles/.env1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a=b
b=a
2 changes: 2 additions & 0 deletions testfiles/.env2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a=b
b=a
1 change: 1 addition & 0 deletions testfiles/.env3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a=b

0 comments on commit b4982ee

Please sign in to comment.