Skip to content

Commit

Permalink
Log message for no search results (#306)
Browse files Browse the repository at this point in the history
* Log message for no search results

* update message
  • Loading branch information
phanimarupaka authored May 14, 2021
1 parent f1f8630 commit bfee82b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions functions/go/search-replace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"os"

"github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/search-replace/searchreplace"
"github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/search-replace/generated"
"github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/search-replace/searchreplace"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
)
Expand Down Expand Up @@ -74,8 +74,13 @@ func getSearchReplaceParams(fc interface{}) (searchreplace.SearchReplace, error)
// equivalent items([]framework.Item)
func searchResultsToItems(sr searchreplace.SearchReplace) []framework.Item {
var items []framework.Item
if len(sr.Results) == 0 {
items = append(items, framework.Item{
Message: "no matches",
})
return items
}
for _, res := range sr.Results {

var message string
if sr.PutComment != "" || sr.PutValue != "" {
message = fmt.Sprintf("Mutated field value to %q", res.Value)
Expand Down
2 changes: 2 additions & 0 deletions tests/search-replace/no-results/simple/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runCount: 2
exitCode: 0
3 changes: 3 additions & 0 deletions tests/search-replace/no-results/simple/.expected/results.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: search-replace
items:
- message: 'no matches'
1 change: 1 addition & 0 deletions tests/search-replace/no-results/simple/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
11 changes: 11 additions & 0 deletions tests/search-replace/no-results/simple/fn-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: my-func-config
annotations:
config.k8s.io/function: |
container:
image: gcr.io/kpt-fn/search-replace:unstable
config.kubernetes.io/local-config: 'true'
data:
by-value: non-existent-value
6 changes: 6 additions & 0 deletions tests/search-replace/no-results/simple/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
some-key: some-value

0 comments on commit bfee82b

Please sign in to comment.