Skip to content

Commit

Permalink
deps: Remove github.com/andybalholm/crlf (#289)
Browse files Browse the repository at this point in the history
Replaced via trivial `strings` handling as the strings are not large.
  • Loading branch information
bflad committed Apr 13, 2022
1 parent facff44 commit 0cf3a0c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion go.mod
Expand Up @@ -3,7 +3,6 @@ module github.com/hashicorp/terraform-exec
go 1.17

require (
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f
github.com/google/go-cmp v0.5.7
github.com/hashicorp/go-version v1.4.0
github.com/hashicorp/hc-install v0.3.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Expand Up @@ -5,8 +5,6 @@ github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C6
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f h1:NNJE6p4LchkmNfNskDUaSbrwxZzr7t2/lj2aS+q4oF0=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
Expand Down
28 changes: 18 additions & 10 deletions tfexec/internal/e2etest/show_test.go
Expand Up @@ -5,11 +5,11 @@ import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"runtime"
"strings"
"testing"

"github.com/andybalholm/crlf"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-version"
tfjson "github.com/hashicorp/terraform-json"
Expand Down Expand Up @@ -588,8 +588,7 @@ func TestShowPlanFileRaw012_linux(t *testing.T) {
t.Skip("plan file created in 0.12 on Linux is not compatible with other systems")
}

// crlf will standardize our line endings for us
f, err := crlf.Open("testdata/non_default_planfile_012/human_readable_output.txt")
f, err := os.Open("testdata/non_default_planfile_012/human_readable_output.txt")
if err != nil {
t.Fatal(err)
}
Expand All @@ -609,16 +608,15 @@ func TestShowPlanFileRaw012_linux(t *testing.T) {
t.Fatal(err)
}

if diff := cmp.Diff(strings.TrimSpace(actual), strings.TrimSpace(string(expected))); diff != "" {
if diff := cmp.Diff(normalizePlanOutput(actual), normalizePlanOutput(string(expected))); diff != "" {
t.Fatalf("unexpected difference: %s", diff)
}
})
}

func TestShowPlanFileRaw013(t *testing.T) {
runTestVersions(t, []string{testutil.Latest013}, "non_default_planfile_013", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
// crlf will standardize our line endings for us
f, err := crlf.Open("testdata/non_default_planfile_013/human_readable_output.txt")
f, err := os.Open("testdata/non_default_planfile_013/human_readable_output.txt")
if err != nil {
t.Fatal(err)
}
Expand All @@ -638,16 +636,15 @@ func TestShowPlanFileRaw013(t *testing.T) {
t.Fatal(err)
}

if diff := cmp.Diff(strings.TrimSpace(actual), strings.TrimSpace(string(expected))); diff != "" {
if diff := cmp.Diff(normalizePlanOutput(actual), normalizePlanOutput(string(expected))); diff != "" {
t.Fatalf("unexpected difference: %s", diff)
}
})
}

func TestShowPlanFileRaw014(t *testing.T) {
runTestVersions(t, []string{testutil.Latest014}, "non_default_planfile_014", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
// crlf will standardize our line endings for us
f, err := crlf.Open("testdata/non_default_planfile_013/human_readable_output.txt")
f, err := os.Open("testdata/non_default_planfile_013/human_readable_output.txt")
if err != nil {
t.Fatal(err)
}
Expand All @@ -666,7 +663,7 @@ func TestShowPlanFileRaw014(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(strings.TrimSpace(actual), strings.TrimSpace(string(expected))); diff != "" {
if diff := cmp.Diff(normalizePlanOutput(actual), normalizePlanOutput(string(expected))); diff != "" {
t.Fatalf("unexpected difference: %s", diff)
}
})
Expand Down Expand Up @@ -739,3 +736,14 @@ func TestShowBigInt(t *testing.T) {
}
})
}

// Since our plan strings are not large, prefer simple cross-platform
// normalization handling over pulling in a dependency.
func normalizePlanOutput(str string) string {
// Ignore any extra newlines at the beginning or end of output
str = strings.TrimSpace(str)
// Normalize CRLF to LF for cross-platform testing
str = strings.Replace(str, "\r\n", "\n", -1)

return str
}

0 comments on commit 0cf3a0c

Please sign in to comment.