-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Breaking: AWS parameter store paths now require dot in property nam…
…e to indicate path in key (/). - New dot-based property name format used to enable grouping and structure output. - Added output tests.
- Loading branch information
1 parent
079294c
commit ea7a4c6
Showing
20 changed files
with
483 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package output_test | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
pio "github.com/dotnetmentor/racoon/internal/io" | ||
"github.com/dotnetmentor/racoon/internal/output" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Dotenv", func() { | ||
Describe("Write", func() { | ||
keys := []string{ | ||
"Foo", | ||
"Bar", | ||
"CamelCasedProperty", | ||
"Path.Based.Property", | ||
"Dotnet.Structured.FormattedProperty", | ||
} | ||
values := map[string]string{ | ||
"Foo": "Bar", | ||
"Bar": "Foo", | ||
"CamelCasedProperty": "Value", | ||
"Path.Based.Property": "Value", | ||
"Dotnet.Structured.FormattedProperty": "Value", | ||
} | ||
|
||
When("writing with defaults", func() { | ||
var result string | ||
|
||
BeforeEach(func() { | ||
_, stdout, _ := pio.Buffered(os.Stdin) | ||
o := output.NewDotenv() | ||
o.Write(stdout, keys, map[string]string{}, values) | ||
b, _ := io.ReadAll(stdout) | ||
result = string(b) | ||
}) | ||
|
||
It("has qouted property", func() { | ||
Expect(result).To(ContainSubstring("FOO=\"Bar\"")) | ||
}) | ||
|
||
It("keeps the sort order", func() { | ||
lines := strings.Split(result, "\n") | ||
Expect(lines[0]).To(ContainSubstring("FOO=")) | ||
Expect(lines[1]).To(ContainSubstring("BAR=")) | ||
Expect(lines[2]).To(ContainSubstring("CAMEL_CASED_PROPERTY=")) | ||
Expect(lines[3]).To(ContainSubstring("PATH_BASED_PROPERTY=")) | ||
Expect(lines[4]).To(ContainSubstring("DOTNET_STRUCTURED_FORMATTED_PROPERTY=")) | ||
}) | ||
}) | ||
|
||
When("writing without quoutes", func() { | ||
var result string | ||
|
||
BeforeEach(func() { | ||
_, stdout, _ := pio.Buffered(os.Stdin) | ||
o := output.NewDotenv() | ||
o.Quote = false | ||
o.Write(stdout, keys, map[string]string{}, values) | ||
b, _ := io.ReadAll(stdout) | ||
result = string(b) | ||
}) | ||
|
||
It("has unquoted property", func() { | ||
Expect(result).To(ContainSubstring("FOO=Bar")) | ||
}) | ||
}) | ||
|
||
When("writing with sorting enabled", func() { | ||
var result string | ||
|
||
BeforeEach(func() { | ||
_, stdout, _ := pio.Buffered(os.Stdin) | ||
o := output.NewDotenv() | ||
o.Sort = true | ||
o.Write(stdout, keys, map[string]string{}, values) | ||
b, _ := io.ReadAll(stdout) | ||
result = string(b) | ||
}) | ||
|
||
It("sorts the output", func() { | ||
lines := strings.Split(result, "\n") | ||
Expect(lines[0]).To(ContainSubstring("BAR=")) | ||
Expect(lines[1]).To(ContainSubstring("CAMEL_CASED_PROPERTY=")) | ||
Expect(lines[2]).To(ContainSubstring("DOTNET_STRUCTURED_FORMATTED_PROPERTY=")) | ||
Expect(lines[3]).To(ContainSubstring("FOO=")) | ||
Expect(lines[4]).To(ContainSubstring("PATH_BASED_PROPERTY=")) | ||
}) | ||
}) | ||
|
||
When("writing with path separator", func() { | ||
var result string | ||
|
||
BeforeEach(func() { | ||
_, stdout, _ := pio.Buffered(os.Stdin) | ||
o := output.NewDotenv() | ||
o.PathSeparator = "__" | ||
o.Write(stdout, keys, map[string]string{}, values) | ||
b, _ := io.ReadAll(stdout) | ||
result = string(b) | ||
}) | ||
|
||
It("sorts the output", func() { | ||
Expect(result).To(ContainSubstring("PATH__BASED__PROPERTY=")) | ||
Expect(result).To(ContainSubstring("DOTNET__STRUCTURED__FORMATTED_PROPERTY=")) | ||
}) | ||
}) | ||
|
||
When("writing dotnet style output", func() { | ||
var result string | ||
|
||
BeforeEach(func() { | ||
_, stdout, _ := pio.Buffered(os.Stdin) | ||
o := output.NewDotenv() | ||
o.Uppercase = false | ||
o.WordSeparator = "" | ||
o.PathSeparator = "__" | ||
o.Write(stdout, keys, map[string]string{}, values) | ||
b, _ := io.ReadAll(stdout) | ||
result = string(b) | ||
}) | ||
|
||
It("sorts the output", func() { | ||
Expect(result).To(ContainSubstring("Path__Based__Property=")) | ||
Expect(result).To(ContainSubstring("Dotnet__Structured__FormattedProperty=")) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package output_test | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
pio "github.com/dotnetmentor/racoon/internal/io" | ||
"github.com/dotnetmentor/racoon/internal/output" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Json", func() { | ||
Describe("Write", func() { | ||
keys := []string{ | ||
"Foo", | ||
"Bar", | ||
"CamelCasedProperty", | ||
"Path.Based.Property", | ||
"Dotnet.Structured.FormattedProperty", | ||
} | ||
values := map[string]string{ | ||
"Foo": "Bar", | ||
"Bar": "Foo", | ||
"CamelCasedProperty": "Value", | ||
"Path.Based.Property": "Value", | ||
"Dotnet.Structured.FormattedProperty": "Value", | ||
} | ||
|
||
When("writing with defaults", func() { | ||
var result string | ||
|
||
BeforeEach(func() { | ||
_, stdout, _ := pio.Buffered(os.Stdin) | ||
o := output.NewJson() | ||
o.Write(stdout, keys, map[string]string{}, values) | ||
b, _ := io.ReadAll(stdout) | ||
result = string(b) | ||
}) | ||
|
||
It("has structured output", func() { | ||
Expect(result).To(MatchJSON(`{"Bar":"Foo","CamelCasedProperty":"Value","Dotnet":{"Structured":{"FormattedProperty":"Value"}},"Foo":"Bar","Path":{"Based":{"Property":"Value"}}}`)) | ||
}) | ||
}) | ||
|
||
When("writing unstructured json", func() { | ||
var result string | ||
|
||
BeforeEach(func() { | ||
_, stdout, _ := pio.Buffered(os.Stdin) | ||
o := output.NewJson() | ||
o.Stuctured = false | ||
o.Write(stdout, keys, map[string]string{}, values) | ||
b, _ := io.ReadAll(stdout) | ||
result = string(b) | ||
}) | ||
|
||
It("has unstructured output", func() { | ||
Expect(result).To(MatchJSON(`{"Bar":"Foo","CamelCasedProperty":"Value","Dotnet.Structured.FormattedProperty":"Value","Foo":"Bar","Path.Based.Property":"Value"}`)) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package output_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestOutput(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Output Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.