From 70815ebaf9ff01195b721f0ba1cf24d099c9b6dc Mon Sep 17 00:00:00 2001 From: Stephen Roylance Date: Mon, 19 Mar 2018 16:34:36 -0400 Subject: [PATCH] hacks for tests on windows --- cmd/kops/create.go | 2 +- cmd/kops/create_cluster_integration_test.go | 3 ++- cmd/kops/integration_test.go | 3 ++- pkg/testutils/integrationtestharness.go | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/kops/create.go b/cmd/kops/create.go index 115aea1ce6..3c3e2bba68 100644 --- a/cmd/kops/create.go +++ b/cmd/kops/create.go @@ -131,7 +131,7 @@ func RunCreate(f *util.Factory, out io.Writer, c *CreateOptions) error { } // TODO: this does not support a JSON array - sections := bytes.Split(contents, []byte("\n---\n")) + sections := bytes.Split(bytes.Replace(contents, []byte("\r\n"), []byte("\n"), -1), []byte("\n---\n")) for _, section := range sections { defaults := &schema.GroupVersionKind{ Group: v1alpha1.SchemeGroupVersion.Group, diff --git a/cmd/kops/create_cluster_integration_test.go b/cmd/kops/create_cluster_integration_test.go index 8e08f1b883..7a4809b200 100644 --- a/cmd/kops/create_cluster_integration_test.go +++ b/cmd/kops/create_cluster_integration_test.go @@ -243,7 +243,8 @@ func runCreateClusterIntegrationTest(t *testing.T, srcDir string, version string t.Fatalf("unexpected error reading expected YAML: %v", err) } - expectedYAML := strings.TrimSpace(string(expectedYAMLBytes)) + //on windows, with git set to autocrlf, the reference files on disk have windows line endings + expectedYAML := strings.Replace(strings.TrimSpace(string(expectedYAMLBytes)), "\r\n", "\n", -1) actualYAML := strings.Join(yamlAll, "\n\n---\n\n") if actualYAML != expectedYAML { diff --git a/cmd/kops/integration_test.go b/cmd/kops/integration_test.go index 54f789f3ba..a33794eae4 100644 --- a/cmd/kops/integration_test.go +++ b/cmd/kops/integration_test.go @@ -251,6 +251,7 @@ func runTest(t *testing.T, h *testutils.IntegrationTestHarness, clusterName stri if err != nil { t.Fatalf("unexpected error reading expected terraform output: %v", err) } + testDataTF = bytes.Replace(testDataTF, []byte("\r\n"), []byte("\n"), -1) if !bytes.Equal(actualTF, testDataTF) { diffString := diff.FormatDiff(string(testDataTF), string(actualTF)) @@ -543,7 +544,7 @@ func runTestCloudformation(t *testing.T, clusterName string, srcDir string, vers } actualCF = buf.Bytes() - expectedCFTrimmed := strings.TrimSpace(string(expectedCF)) + expectedCFTrimmed := strings.Replace(strings.TrimSpace(string(expectedCF)), "\r\n", "\n", -1) actualCFTrimmed := strings.TrimSpace(string(actualCF)) if actualCFTrimmed != expectedCFTrimmed { diffString := diff.FormatDiff(expectedCFTrimmed, actualCFTrimmed) diff --git a/pkg/testutils/integrationtestharness.go b/pkg/testutils/integrationtestharness.go index aae2dc90b4..58d75cca4a 100644 --- a/pkg/testutils/integrationtestharness.go +++ b/pkg/testutils/integrationtestharness.go @@ -68,7 +68,9 @@ func NewIntegrationTestHarness(t *testing.T) *IntegrationTestHarness { } channelPath += "/" h.originalDefaultChannelBase = kops.DefaultChannelBase - kops.DefaultChannelBase = "file://" + channelPath + + // Make sure any platform-specific separators that aren't /, are converted to / for use in a file: protocol URL + kops.DefaultChannelBase = "file://" + filepath.ToSlash(channelPath) } return h