Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit bd5c215

Browse files
authored
feat: strings exprs support ToUpper and ToLower function (#364)
* feat: strings exprs support ToUpper and ToLower function Signed-off-by: Viet-Anh Duong <vietanhs0817@gmail.com> * docs: add ToLower and ToUpper document Signed-off-by: Viet-Anh Duong <vietanhs0817@gmail.com>
1 parent de62f9e commit bd5c215

File tree

3 files changed

+84
-13
lines changed

3 files changed

+84
-13
lines changed

docs/functions.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
### **time**
2+
23
Time related functions.
34

45
<hr>
56
**`time.Now() Time`**
67

7-
Executes function built-in Golang [time.Now](https://golang.org/pkg/time/#Now) function.
8-
Returns an instance of Golang [Time](https://golang.org/pkg/time/#Time).
8+
Executes function built-in Golang [time.Now](https://golang.org/pkg/time/#Now) function. Returns an instance of
9+
Golang [Time](https://golang.org/pkg/time/#Time).
910

1011
<hr>
1112
**`time.Parse(val string) Time`**
1213

1314
Parses specified string using RFC3339 layout. Returns an instance of Golang [Time](https://golang.org/pkg/time/#Time).
1415

1516
### **strings**
17+
1618
String related functions.
1719

1820
<hr>
1921
**`strings.ReplaceAll() string`**
2022

2123
Executes function built-in Golang [strings.ReplaceAll](https://pkg.go.dev/strings#ReplaceAll) function.
2224

25+
<hr>
26+
**`strings.ToUpper() string`**
27+
28+
Executes function built-in Golang [strings.ToUpper](https://pkg.go.dev/strings#ToUpper) function.
29+
30+
<hr>
31+
**`strings.ToLower() string`**
32+
33+
Executes function built-in Golang [strings.ToLower](https://pkg.go.dev/strings#ToLower) function.
34+
2335
### **sync**
2436

2537
<hr>
@@ -28,6 +40,7 @@ Executes function built-in Golang [strings.ReplaceAll](https://pkg.go.dev/string
2840
Returns the `info` item value by given name stored in the Argo CD App sync operation.
2941

3042
### **repo**
43+
3144
Functions that provide additional information about Application source repository.
3245
<hr>
3346
**`repo.RepoURLToHTTPS(url string) string`**
@@ -46,7 +59,7 @@ Returns commit metadata. The commit must belong to the application source reposi
4659

4760
* `Message string` commit message
4861
* `Author string` - commit author
49-
* `Date time.Time` - commit creation date
62+
* `Date time.Time` - commit creation date
5063
* `Tags []string` - Associated tags
5164

5265
<hr>
@@ -56,15 +69,15 @@ Returns application details. `AppDetail` fields:
5669

5770
* `Type string` - AppDetail type
5871
* `Helm HelmAppSpec` - Helm details
59-
* Fields :
60-
* `Name string`
61-
* `ValueFiles []string`
62-
* `Parameters []*v1alpha1.HelmParameter`
63-
* `Values string`
64-
* `FileParameters []*v1alpha1.HelmFileParameter`
65-
* Methods :
66-
* `GetParameterValueByName(Name string)` Retrieve value by name in Parameters field
67-
* `GetFileParameterPathByName(Name string)` Retrieve path by name in FileParameters field
72+
* Fields :
73+
* `Name string`
74+
* `ValueFiles []string`
75+
* `Parameters []*v1alpha1.HelmParameter`
76+
* `Values string`
77+
* `FileParameters []*v1alpha1.HelmFileParameter`
78+
* Methods :
79+
* `GetParameterValueByName(Name string)` Retrieve value by name in Parameters field
80+
* `GetFileParameterPathByName(Name string)` Retrieve path by name in FileParameters field
6881
* `Ksonnet *apiclient.KsonnetAppSpec` - Ksonnet details
6982
* `Kustomize *apiclient.KustomizeAppSpec` - Kustomize details
7083
* `Directory *apiclient.DirectoryAppSpec` - Directory details

expr/strings/strings.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package strings
22

3-
import "strings"
3+
import (
4+
"strings"
5+
)
46

57
func NewExprs() map[string]interface{} {
68
return map[string]interface{}{
79
"ReplaceAll": replaceAll,
10+
"ToUpper": toUpper,
11+
"ToLower": toLower,
812
}
913
}
1014

1115
func replaceAll(s, old, new string) string {
1216
return strings.ReplaceAll(s, old, new)
1317
}
18+
19+
func toUpper(s string) string {
20+
return strings.ToUpper(s)
21+
}
22+
23+
func toLower(s string) string {
24+
return strings.ToLower(s)
25+
}

expr/strings/strings_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package strings
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -9,6 +10,8 @@ import (
910
func TestNewExprs(t *testing.T) {
1011
funcs := []string{
1112
"ReplaceAll",
13+
"ToUpper",
14+
"ToLower",
1215
}
1316

1417
for _, fn := range funcs {
@@ -17,3 +20,46 @@ func TestNewExprs(t *testing.T) {
1720
assert.True(t, hasFunc)
1821
}
1922
}
23+
24+
func TestReplaceAll(t *testing.T) {
25+
exprs := NewExprs()
26+
27+
input := "test_replace"
28+
expected := "test=replace"
29+
replaceAllFn, ok := exprs["ReplaceAll"].(func(s, old, new string) string)
30+
assert.True(t, ok)
31+
32+
actual := replaceAllFn(input, "_", "=")
33+
assert.Equal(t, expected, actual)
34+
}
35+
36+
func TestUpperAndLower(t *testing.T) {
37+
testCases := []struct {
38+
fn string
39+
input string
40+
expected string
41+
}{
42+
{
43+
fn: "ToUpper",
44+
input: "test",
45+
expected: "TEST",
46+
},
47+
{
48+
fn: "ToLower",
49+
input: "TEST",
50+
expected: "test",
51+
},
52+
}
53+
exprs := NewExprs()
54+
55+
for _, testCase := range testCases {
56+
t.Run(fmt.Sprintf("With success case: Func: %s", testCase.fn), func(tc *testing.T) {
57+
toUpperFn, ok := exprs[testCase.fn].(func(s string) string)
58+
assert.True(t, ok)
59+
60+
actual := toUpperFn(testCase.input)
61+
assert.Equal(t, testCase.expected, actual)
62+
})
63+
}
64+
65+
}

0 commit comments

Comments
 (0)