Skip to content

Commit

Permalink
wip 3
Browse files Browse the repository at this point in the history
  • Loading branch information
aabouzaid committed Sep 18, 2023
1 parent 1f59faa commit e77ca1d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7815/badge)](https://www.bestpractices.dev/projects/7815)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/aabouzaid/kustomize-plugin-merger/badge)](https://securityscorecards.dev/viewer/?uri=github.com/aabouzaid/kustomize-plugin-merger)
[![Go Report Card](https://goreportcard.com/badge/github.com/aabouzaid/kustomize-plugin-merger)](https://goreportcard.com/report/github.com/aabouzaid/kustomize-plugin-merger)
[![codecov](https://codecov.io/github/aabouzaid/kustomize-plugin-merger/graph/badge.svg?token=BUFRT7BO2I)](https://codecov.io/github/aabouzaid/kustomize-plugin-merger)
[![GitHub Release](https://img.shields.io/github/v/release/aabouzaid/kustomize-plugin-merger?logo=github)](https://github.com/aabouzaid/kustomize-plugin-merger/releases)
[![Docker](https://img.shields.io/badge/Docker-available-blue?logo=docker&logoColor=white)](https://github.com/aabouzaid/kustomize-plugin-merger/pkgs/container/kustomize-generator-merger)
[![Go Reference](https://pkg.go.dev/badge/github.com/aabouzaid/kustomize-plugin-merger.svg)](https://pkg.go.dev/github.com/aabouzaid/kustomize-plugin-merger)
[![Renovatebot](https://img.shields.io/badge/Renovate-enabled-blue?logo=renovatebot)](https://github.com/aabouzaid/kustomize-plugin-merger/issues/7)
[![Renovate](https://img.shields.io/badge/Renovate-enabled-blue?logo=renovatebot)](https://github.com/aabouzaid/kustomize-plugin-merger/issues/7)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/aabouzaid/kustomize-plugin-merger/pulls)

<!-- omit in toc -->
Expand Down
8 changes: 4 additions & 4 deletions pkg/merger/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (rif *resourceInputFiles) setRoot() {
}
}

func (r *mergerResource) loadDestinationFile() *koanf.Koanf {
func (rif *resourceInputFiles) loadDestinationFile() *koanf.Koanf {
k := koanf.New(".")
dstFile := r.Input.Files.Root + r.Input.Files.Destination
dstFile := rif.Root + rif.Destination
if err := k.Load(koanfFile.Provider(dstFile), koanfYaml.Parser()); err != nil {
log.Fatalf("Error loading config: %v", err)
}
Expand All @@ -45,14 +45,14 @@ func (r *mergerResource) loadDestinationFile() *koanf.Koanf {
// merge performs the actual merging of configuration files from resourceInputFiles sources.
func (r *mergerResource) merge() {
// TODO: Simplify/split the logic in merge method.
k := r.loadDestinationFile()
k := r.Input.Files.loadDestinationFile()
fileKey := r.Name

for _, srcFile := range r.Input.Files.Sources {
srcFile = r.Input.Files.Root + srcFile

if r.Input.Method == Overlay {
k = r.loadDestinationFile()
k = r.Input.Files.loadDestinationFile()
fileKey = filepath.Base(srcFile)
}

Expand Down
25 changes: 23 additions & 2 deletions pkg/merger/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestSetMergeStrategy(t *testing.T) {
expected := runtime.FuncForPC(reflect.ValueOf(tt.expected).Pointer()).Name()

assert.Equal(t, expected, actual,
"Expected config to be %v, but got %v", tt.expected, tt.actual.config)
"Expected to be %v, but got %v", tt.expected, tt.actual.config)
}
}

Expand Down Expand Up @@ -72,6 +72,27 @@ func TestSetRoot(t *testing.T) {
for _, tt := range tests {
tt.actual.setRoot()
assert.Equal(t, tt.expected, tt.actual.Root,
"Expected root to be %v, but got %v", tt.expected, tt.actual)
"Expected to be %v, but got %v", tt.expected, tt.actual)
}
}

func TestLoadDestinationFile(t *testing.T) {
tests := []struct {
actual resourceInputFiles
expected string
}{
{
actual: resourceInputFiles{
Root: "./",
Destination: "testdata/test_load_destination_file.yaml",
},
expected: "foo",
},
}

for _, tt := range tests {
k := tt.actual.loadDestinationFile()
assert.Contains(t, k.Keys(), tt.expected,
"Expected to be %v, but got %v", tt.expected, tt.actual)
}
}
1 change: 1 addition & 0 deletions pkg/merger/testdata/test_load_destination_file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo: bar

0 comments on commit e77ca1d

Please sign in to comment.