Skip to content

Commit

Permalink
wip 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aabouzaid committed Sep 18, 2023
1 parent 60e8c47 commit 1f59faa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ permissions:
contents: read

jobs:
lint:
name: Lint Code
lint-and-test:
name: Lint And Test Code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4
with:
go-version-file: go.mod
cache: false
- name: Run GolangCI Linter
- name: Run GolangCI linter
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3
with:
version: v1.54
- name: Run Go test coverage
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

build:
name: Build Artifacts
needs: ["lint-and-test"]
permissions:
id-token: write
contents: write
packages: write
pull-requests: write
needs: ["lint"]
uses: ./.github/workflows/tpl-packaging.yml
secrets: inherit
with:
Expand Down
2 changes: 1 addition & 1 deletion pkg/merger/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (m *Merger) Schema() (*spec.Schema, error) {
func (m *Merger) Default() error {
for index := range m.Spec.Resources {
//
m.Spec.Resources[index].setInputFilesRoot()
m.Spec.Resources[index].Input.Files.setRoot()
// Defaults merge strategy.
m.Spec.Resources[index].Merge.setStrategy()
// Create empty map for staged data.
Expand Down
6 changes: 3 additions & 3 deletions pkg/merger/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (rm *resourceMerge) setStrategy() {
}
}

func (r *mergerResource) setInputFilesRoot() {
if r.Input.Files.Root != "" {
r.Input.Files.Root = strings.TrimSuffix(r.Input.Files.Root, "/") + "/"
func (rif *resourceInputFiles) setRoot() {
if rif.Root != "" {
rif.Root = strings.TrimSuffix(rif.Root, "/") + "/"
}
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/merger/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,35 @@ func TestSetMergeStrategy(t *testing.T) {
"Expected config to be %v, but got %v", tt.expected, tt.actual.config)
}
}

func TestSetRoot(t *testing.T) {
tests := []struct {
actual resourceInputFiles
expected string
}{
{
actual: resourceInputFiles{
Root: "/mnt",
},
expected: "/mnt/",
},
{
actual: resourceInputFiles{
Root: "/mnt/",
},
expected: "/mnt/",
},
{
actual: resourceInputFiles{
Root: "my-dir",
},
expected: "my-dir/",
},
}

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)
}
}

0 comments on commit 1f59faa

Please sign in to comment.