Skip to content

Commit

Permalink
adds unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RafPe committed Feb 16, 2023
1 parent c0e9c95 commit 546f2e2
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions merge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// file: main_test.go
package main

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestMergeYAML_TwoFiles(t *testing.T) {
result, err := MergeYAML("tests/test1.yaml", "tests/test2.yaml")
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(`
modules:
my_module:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
my_module2:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
my_module3:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
providers:
my_provider:
auth:
ssh_key: ssh:key:2312312
providerType: github
`), strings.TrimSpace(result))
}

func TestMergeYAML_MissingFile(t *testing.T) {
result, err := MergeYAML("tests/test1.yaml", "tests/test3.yaml")
assert.Error(t, err)
assert.Contains(t, err.Error(), "no such file or directory")
assert.Equal(t, "", result)
}

func TestMergeYAML_InvalidYAML(t *testing.T) {
result, err := MergeYAML("tests/test1.yaml", "tests/invalid.yaml")
assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to unmarshal data from file")
assert.Equal(t, "", result)
}

0 comments on commit 546f2e2

Please sign in to comment.