-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bird <aflybird0@gmail.com>
- Loading branch information
Showing
5 changed files
with
213 additions
and
33 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
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 |
---|---|---|
@@ -1,27 +1,149 @@ | ||
package template | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestAddDotForVariablesInConfigNormal(t *testing.T) { | ||
res := addDotForVariablesInConfig("[[varNameA]]") | ||
assert.Equal(t, "[[ .varNameA]]", res, "Adding dot for variable names passed.") | ||
} | ||
|
||
func TestAddDotForVariablesInConfigWithSpaces(t *testing.T) { | ||
res := addDotForVariablesInConfig("[[ varNameA]]") | ||
assert.Equal(t, "[[ .varNameA]]", res, "Adding dot for variable names passed.") | ||
} | ||
|
||
func TestAddDotForVariablesInConfigWithTrailingSpaces(t *testing.T) { | ||
res := addDotForVariablesInConfig("[[ varNameA ]]") | ||
assert.Equal(t, "[[ .varNameA ]]", res, "Adding dot for variable names passed.") | ||
} | ||
|
||
func TestAddDotForVariablesInConfigMultipleVars(t *testing.T) { | ||
res := addDotForVariablesInConfig("[[ varNameA ]]/[[ varNameB ]]/[[ varNameC ]]") | ||
assert.Equal(t, "[[ .varNameA ]]/[[ .varNameB ]]/[[ .varNameC ]]", res, "Adding dot for variable names passed.") | ||
} | ||
var _ = Describe("addDotForVariablesInConfig", func() { | ||
var ( | ||
origin, gotten, expected string | ||
) | ||
|
||
JustBeforeEach(func() { | ||
gotten = addDotForVariablesInConfig(origin) | ||
}) | ||
|
||
When("config is normal", func() { | ||
BeforeEach(func() { | ||
origin = "[[varNameA]]" | ||
expected = "[[ .varNameA ]]" | ||
}) | ||
It("should succeed", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("config has spaces", func() { | ||
BeforeEach(func() { | ||
origin = "[[ varNameA ]]" | ||
expected = "[[ .varNameA ]]" | ||
}) | ||
|
||
It("should succeed", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("config has trailing spaces", func() { | ||
BeforeEach(func() { | ||
origin = "[[ varNameA ]]" | ||
expected = "[[ .varNameA ]]" | ||
}) | ||
|
||
It("should succeed", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("config has multiple variables", func() { | ||
BeforeEach(func() { | ||
origin = "[[ varNameA ]]/[[ varNameB ]]/[[ varNameC ]]" | ||
expected = "[[ .varNameA ]]/[[ .varNameB ]]/[[ .varNameC ]]" | ||
}) | ||
|
||
It("should succeed", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("there are more than one words", func() { | ||
BeforeEach(func() { | ||
origin = "[[ func varNameA ]]" | ||
expected = origin | ||
}) | ||
|
||
It("should do nothing", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
}) | ||
|
||
var _ = Describe("addQuoteForVariablesInConfig", func() { | ||
var ( | ||
origin, gotten, expected string | ||
) | ||
|
||
JustBeforeEach(func() { | ||
gotten = addQuoteForVariablesInConfig(origin) | ||
}) | ||
AfterEach(func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
|
||
When("config is normal", func() { | ||
BeforeEach(func() { | ||
origin = `[[env GITHUB_TOKEN]]` | ||
expected = `[[ env "GITHUB_TOKEN" ]]` | ||
}) | ||
|
||
It("should succeed", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("config has single quote", func() { | ||
BeforeEach(func() { | ||
origin = `[[ env 'GITHUB_TOKEN']]` | ||
expected = origin | ||
}) | ||
|
||
It("should do nothing", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("config has quote", func() { | ||
BeforeEach(func() { | ||
origin = `[[ env "GITHUB_TOKEN"]]` | ||
expected = origin | ||
}) | ||
|
||
It("should do nothing", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("config has multiple variables", func() { | ||
BeforeEach(func() { | ||
origin = `[[ env GITHUB_TOKEN]]/[[ env "GITLAB_TOKEN"]]` | ||
expected = `[[ env "GITHUB_TOKEN" ]]/[[ env "GITLAB_TOKEN"]]` | ||
}) | ||
|
||
It("should succeed", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("the first word has quote", func() { | ||
BeforeEach(func() { | ||
origin = `[[ "env" GITHUB_TOKEN]]` | ||
expected = origin | ||
}) | ||
|
||
It("should do nothing", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
|
||
When("there is only one word", func() { | ||
BeforeEach(func() { | ||
origin = `[[GITHUB_TOKEN]]` | ||
expected = origin | ||
}) | ||
|
||
It("should do nothing", func() { | ||
Expect(gotten).To(Equal(expected)) | ||
}) | ||
}) | ||
}) |
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