-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomasz Gągor
committed
Dec 28, 2024
1 parent
f576c71
commit bd0c700
Showing
5 changed files
with
169 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tgagor/template-dockerfiles/pkg/cmd" | ||
) | ||
|
||
func TestRunner(t *testing.T) { | ||
// Arrange | ||
input := []string{ | ||
cmd.New("echo").Arg("hello").Arg("world").String(), | ||
cmd.New("cmd-only").String(), | ||
cmd.New("").String(), | ||
} | ||
expected := []string{ | ||
"echo hello world", | ||
"cmd-only", | ||
"", | ||
} | ||
|
||
// Assert | ||
for i, input := range input { | ||
assert.Equal(t, expected[i], input) | ||
} | ||
} |
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,78 @@ | ||
package parser_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tgagor/template-dockerfiles/pkg/parser" | ||
) | ||
|
||
func TestTemplateString(t *testing.T) { | ||
// Arrange | ||
inputStrings := []string{ | ||
"{{ .key }}", | ||
"{{ .key }}", | ||
"{{ .key }}", | ||
" {{ .key }} ", | ||
"{{ .sprig | default \"works\" }}", | ||
"{{range .loop}}{{.}}{{ end }}", | ||
} | ||
inputArgs := []map[string]interface{}{ | ||
{"key": "value"}, | ||
{"key": 1}, | ||
{"key": 1.43}, | ||
{"key": "value"}, | ||
{"sprig": ""}, | ||
{"loop": []int{1, 2, 3}}, | ||
} | ||
|
||
expected := []string{ | ||
"value", | ||
"1", | ||
"1.43", | ||
" value ", | ||
"works", | ||
"123", | ||
} | ||
|
||
// Assert | ||
for i, input := range inputStrings { | ||
result, _ := parser.TemplateString(input, inputArgs[i]) | ||
assert.Equal(t, expected[i], result) | ||
} | ||
} | ||
|
||
// func TestTemplateTags(t *testing.T) { | ||
// // Arrange | ||
// input := []string{ | ||
// "{{ .key1 }}", | ||
// "{{ .key2 }}", | ||
// "{{ .key3 }}", | ||
// " {{ .key4 }} ", | ||
// "{{ .sprig | default \"works\" }}", | ||
// "{{range .loop}}{{.}}{{ end }}", | ||
// } | ||
// args := map[string]interface{}{ | ||
// "key1": "value", | ||
// "key2": 1, | ||
// "key3": 1.43, | ||
// "key4": "value", | ||
// "sprig": "", | ||
// "loop": []int{1, 2, 3}, | ||
// } | ||
|
||
// expected := []string{ | ||
// "value", | ||
// "1", | ||
// "1.43", | ||
// " value ", | ||
// "works", | ||
// "123", | ||
// } | ||
|
||
// // Assert | ||
// for i, input := range inputStrings { | ||
// result, _ := parser.TemplateTags(input) | ||
// assert.Equal(t, expected[i], result) | ||
// } | ||
// } |
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,58 @@ | ||
package util_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tgagor/template-dockerfiles/pkg/util" | ||
) | ||
|
||
func TestByteCountIEC(t *testing.T) { | ||
// Arrange | ||
input := []uint64{ | ||
1000, | ||
1024, | ||
1000 * 1000, | ||
1024 * 1024, | ||
1000 * 1000 * 1000, | ||
1024 * 1024 * 1024, | ||
} | ||
expected := []string{ | ||
"1000 B", | ||
"1.0 KiB", | ||
"976.6 KiB", | ||
"1.0 MiB", | ||
"953.7 MiB", | ||
"1.0 GiB", | ||
} | ||
|
||
// Assert | ||
for i, input := range input { | ||
assert.Equal(t, expected[i], util.ByteCountIEC(input)) | ||
} | ||
} | ||
|
||
func TestByteCountSI(t *testing.T) { | ||
// Arrange | ||
input := []uint64{ | ||
1000, | ||
1024, | ||
1000 * 1000, | ||
1024 * 1024, | ||
1000 * 1000 * 1000, | ||
1024 * 1024 * 1024, | ||
} | ||
expected := []string{ | ||
"1.0 kB", | ||
"1.0 kB", | ||
"1.0 MB", | ||
"1.0 MB", | ||
"1.0 GB", | ||
"1.1 GB", | ||
} | ||
|
||
// Assert | ||
for i, input := range input { | ||
assert.Equal(t, expected[i], util.ByteCountSI(input)) | ||
} | ||
} |