Skip to content

Commit

Permalink
Fix download-source test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
brikis98 committed Jan 30, 2017
1 parent d60f47c commit ab12052
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
65 changes: 33 additions & 32 deletions cli/download_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,64 +83,65 @@ func TestDownloadTerraformSourceIfNecessaryLocalDirToAlreadyDownloadedDir(t *tes
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

copyFolder(t, "../test/fixture-downlooad-source/hello-world-2", downloadDir)
copyFolder(t, "../test/fixture-download-source/hello-world-2", downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World")
}

func TestDownloadTerraformSourceIfNecessaryRemoteUrlToEmptyDir(t *testing.T) {
t.Parallel()

// TODO: update URL to master branch once this is merged
canonicalUrl := "https://github.com/gruntwork-io/terragrunt/tree/cache-tmp-folder/test/fixture-download-source/hello-world"
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World")
}

func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDir(t *testing.T) {
t.Parallel()

// TODO: update URL to master branch once this is merged
canonicalUrl := "https://github.com/gruntwork-io/terragrunt/tree/cache-tmp-folder/test/fixture-download-source/hello-world-2"
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

copyFolder(t, "../test/fixture-downlooad-source/hello-world-2", downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World")
}
// TODO re-enable these two tests once this is merged into master, since they are trying to download code from master
//func TestDownloadTerraformSourceIfNecessaryRemoteUrlToEmptyDir(t *testing.T) {
// t.Parallel()
//
// // TODO: update URL to master branch once this is merged
// canonicalUrl := "github.com/gruntwork-io/terragrunt//test/fixture-download-source/hello-world"
// downloadDir := tmpDir(t)
// defer os.Remove(downloadDir)
//
// testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World")
//}
//
//func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDir(t *testing.T) {
// t.Parallel()
//
// // TODO: update URL to master branch once this is merged
// canonicalUrl := "github.com/gruntwork-io/terragrunt//test/fixture-download-source/hello-world"
// downloadDir := tmpDir(t)
// defer os.Remove(downloadDir)
//
// copyFolder(t, "../test/fixture-download-source/hello-world-2", downloadDir)
//
// testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World 2")
//}

func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDirDifferentVersion(t *testing.T) {
t.Parallel()

// TODO: update URL to master branch once this is merged
canonicalUrl := "https://github.com/gruntwork-io/terragrunt/tree/cache-tmp-folder/test/fixture-download-source/hello-world-2?ref=v0.0.3"
canonicalUrl := "github.com/gruntwork-io/terragrunt//test/fixture-download-source/hello-world?ref=cache-tmp-folder"
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

copyFolder(t, "../test/fixture-downlooad-source/hello-world-2", downloadDir)
copyFolder(t, "../test/fixture-download-source/hello-world-2", downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World 2")
testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World")
}

func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDirSameVersion(t *testing.T) {
t.Parallel()

// TODO: update URL to master branch once this is merged
canonicalUrl := "https://github.com/gruntwork-io/terragrunt/tree/cache-tmp-folder/test/fixture-download-source/hello-world-2?ref=v0.0.3"
canonicalUrl := "github.com/gruntwork-io/terragrunt//test/fixture-download-source/hello-world?ref=cache-tmp-folder"
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

copyFolder(t, "../test/fixture-downlooad-source/hello-world-ref-v0.0.3", downloadDir)
copyFolder(t, "../test/fixture-download-source/hello-world-version-remote", downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World")
testDownloadTerraformSourceIfNecessary(t, canonicalUrl, downloadDir, "# Hello, World version remote")
}

func testDownloadTerraformSourceIfNecessary(t *testing.T, canonicalUrl string, downloadDir string, expectedFileContents string) {
terraformSource := &TerraformSource{
CanonicalSourceURL: canonicalUrl,
CanonicalSourceURL: parseUrl(t, canonicalUrl),
DownloadDir: downloadDir,
VersionFile: filepath.Join(downloadDir, "version-file.txt"),
}
Expand All @@ -163,7 +164,7 @@ func testAlreadyHaveLatestCode(t *testing.T, canonicalUrl string, downloadDir st
}

actual, err := alreadyHaveLatestCode(terraformSource)
assert.Nil(t, err, "Unexpected error for terraform source %v: %v", err, terraformSource)
assert.Nil(t, err, "Unexpected error for terraform source %v: %v", terraformSource, err)
assert.Equal(t, expected, actual, "For terraform source %v", terraformSource)
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hello, World version remote
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s7cjjCUtiLre6qopc6Z_GIdMmJ8=

0 comments on commit ab12052

Please sign in to comment.