Skip to content

Commit

Permalink
fix: replace newline for test case on windows
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe committed Dec 25, 2023
1 parent 59603b4 commit deb86e0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,18 +910,24 @@ func TestAddWithDiffVersionNoSumCheck(t *testing.T) {
assert.Equal(t, utils.DirExists(pkgWithSumCheckPathModLock), false)

modContent, err := os.ReadFile(pkgWithSumCheckPathMod)
modContentStr := strings.ReplaceAll(string(modContent), "\r\n", "")
modContentStr = strings.ReplaceAll(string(modContentStr), "\n", "")
assert.Equal(t, err, nil)
modExpectContent, err := os.ReadFile(pkgWithSumCheckPathModExpect)
modExpectContentStr := strings.ReplaceAll(string(modExpectContent), "\r\n", "")
modExpectContentStr = strings.ReplaceAll(modExpectContentStr, "\n", "")
assert.Equal(t, err, nil)
assert.Equal(t, string(modContent), string(modExpectContent))
assert.Equal(t, modContentStr, modExpectContentStr)

opts.NoSumCheck = false
_, err = kpmcli.AddDepWithOpts(kclPkg, &opts)
assert.Equal(t, err, nil)
assert.Equal(t, utils.DirExists(pkgWithSumCheckPathModLock), true)
modContent, err = os.ReadFile(pkgWithSumCheckPathMod)
modContentStr = strings.ReplaceAll(string(modContent), "\r\n", "")
modContentStr = strings.ReplaceAll(modContentStr, "\n", "")
assert.Equal(t, err, nil)
assert.Equal(t, string(modContent), string(modExpectContent))
assert.Equal(t, modContentStr, modExpectContentStr)

defer func() {
_ = os.Remove(pkgWithSumCheckPathMod)
Expand Down Expand Up @@ -966,16 +972,26 @@ func TestAddWithDiffVersionWithSumCheck(t *testing.T) {
assert.Equal(t, err, nil)

modContent, err := os.ReadFile(pkgWithSumCheckPathMod)
modContentStr := strings.ReplaceAll(string(modContent), "\r\n", "")
modContentStr = strings.ReplaceAll(modContentStr, "\n", "")
assert.Equal(t, err, nil)

modExpectContent, err := os.ReadFile(pkgWithSumCheckPathModExpect)
modExpectContentStr := strings.ReplaceAll(string(modExpectContent), "\r\n", "")
modExpectContentStr = strings.ReplaceAll(modExpectContentStr, "\n", "")

assert.Equal(t, err, nil)
assert.Equal(t, string(modContent), string(modExpectContent))
assert.Equal(t, modContentStr, modExpectContentStr)

modLockContent, err := os.ReadFile(pkgWithSumCheckPathModLock)
modLockContentStr := strings.ReplaceAll(string(modLockContent), "\r\n", "")
modLockContentStr = strings.ReplaceAll(modLockContentStr, "\n", "")
assert.Equal(t, err, nil)
modLockExpectContent, err := os.ReadFile(pkgWithSumCheckPathModLockExpect)
modLockExpectContentStr := strings.ReplaceAll(string(modLockExpectContent), "\r\n", "")
modLockExpectContentStr = strings.ReplaceAll(modLockExpectContentStr, "\n", "")
assert.Equal(t, err, nil)
assert.Equal(t, string(modLockContent), string(modLockExpectContent))
assert.Equal(t, modLockContentStr, modLockExpectContentStr)

defer func() {
_ = os.Remove(pkgWithSumCheckPathMod)
Expand Down

0 comments on commit deb86e0

Please sign in to comment.