Skip to content

Commit

Permalink
Add a run test
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki committed Oct 3, 2021
1 parent c88126e commit 966b704
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions pkg/gitkustomizediff/run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2021 Daisuke Taniwaki.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package gitkustomizediff

import (
"io/ioutil"
"os"
"strings"
"testing"

"github.com/dtaniwaki/git-kustomize-diff/pkg/utils"
"github.com/stretchr/testify/assert"
)

var (
exampleRepoUrl = "https://github.com/dtaniwaki/git-kustomize-diff-example.git"
)

func TestRun(t *testing.T) {
expectedFooDiff := strings.TrimLeft(`
@@ -5,4 +5,4 @@
spec:
containers:
- image: nginx:latest
- name: foo-modified
+ name: foo-in-branch
`, "\n")
tmpGitDir, err := ioutil.TempDir("", "kustomize-diff-test-")
if !assert.NoError(t, err) {
t.FailNow()
}
defer os.RemoveAll(tmpGitDir)
workDir := &utils.WorkDir{
Dir: tmpGitDir,
}
_, _, err = workDir.RunCommand("git", "clone", exampleRepoUrl, tmpGitDir)
if !assert.NoError(t, err) {
t.FailNow()
}
diffMap, err := Run(tmpGitDir, RunOpts{
Base: "origin/main",
Target: "origin/a-branch",
Debug: true,
})
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, []string{"foo"}, diffMap.Dirs())
assert.Equal(t, expectedFooDiff, diffMap.Results["foo"].ToString())
}

0 comments on commit 966b704

Please sign in to comment.