Skip to content

Commit

Permalink
use official d8 release for testing (#503)
Browse files Browse the repository at this point in the history
* use official d8 release for testing

* updates d8 test site config, update Prepare() to handle no existing conf file

* removes invalid test case for invalid test site prepare

* adds test for GetCachedArchive
  • Loading branch information
tannerjfco committed Oct 16, 2017
1 parent 84e1281 commit fd5b699
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
6 changes: 3 additions & 3 deletions pkg/plugins/platform/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ var (
},
{
Name: "TestMainPkgDrupal8",
SourceURL: "https://github.com/drud/drupal8/archive/v0.6.0.tar.gz",
ArchiveInternalExtractionPath: "drupal8-0.6.0/",
SourceURL: "https://ftp.drupal.org/files/projects/drupal-8.4.0.tar.gz",
ArchiveInternalExtractionPath: "drupal-8.4.0/",
FilesTarballURL: "https://github.com/drud/drupal8/releases/download/v0.6.0/files.tar.gz",
FilesZipballURL: "https://github.com/drud/drupal8/releases/download/v0.6.0/files.zip",
DBTarURL: "https://github.com/drud/drupal8/releases/download/v0.6.0/db.tar.gz",
DBZipURL: "https://github.com/drud/drupal8/releases/download/v0.6.0/db.zip",
FullSiteTarballURL: "https://github.com/drud/drupal8/releases/download/v0.6.0/site.tar.gz",
DocrootBase: "docroot",
AppType: "drupal8",
},
{
Name: "TestMainPkgDrupalKickstart",
Expand Down
38 changes: 21 additions & 17 deletions pkg/testcommon/testcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type TestSite struct {
HTTPProbeURI string
// DocrootBase is the subdirectory witin the site that is the root/index.php
DocrootBase string
// AppType is the type of application. This can be specified when a config file is not present
// for a test site.
AppType string
}

// Prepare downloads and extracts a site codebase to a temporary directory.
Expand Down Expand Up @@ -74,21 +77,21 @@ func (site *TestSite) Prepare() error {
return fmt.Errorf("Failed to CopyDir from %s to %s, err=%v", cachedSrcDir, site.Dir, err)
}

// If our test site has a Name: then update the config file to reflect that.
if site.Name != "" {
config, err := ddevapp.NewConfig(site.Dir, "")
if err != nil {
return errors.Errorf("Failed to read site config for site %s, dir %s, err:%v", site.Name, site.Dir, err)
}
err = config.Read()
if err != nil {
return errors.Errorf("Failed to read site config for site %s, dir %s, err: %v", site.Name, site.Dir, err)
}
config.Name = site.Name
err = config.Write()
if err != nil {
return errors.Errorf("Failed to write site config for site %s, dir %s, err: %v", site.Name, site.Dir, err)
}
// Create a config object. Err is ignored as we may not have
// a config file to read in from a test site.
config, _ := ddevapp.NewConfig(site.Dir, "")

// Set site name to the name we define for test sites. We'll
// ignore site name defined in config file if present.
config.Name = site.Name

if config.AppType == "" {
config.AppType = site.AppType
}

err = config.Write()
if err != nil {
return errors.Errorf("Failed to write site config for site %s, dir %s, err: %v", site.Name, site.Dir, err)
}

runTime()
Expand Down Expand Up @@ -271,7 +274,7 @@ func GetCachedArchive(siteName string, prefixString string, internalExtractionPa
_ = os.MkdirAll(extractPath, 0777)
err := util.DownloadFile(archiveFullPath, sourceURL, false)
if err != nil {
return "", "", fmt.Errorf("Failed to download url=%s into %s, err=%v", sourceURL, archiveFullPath, err)
return extractPath, archiveFullPath, fmt.Errorf("Failed to download url=%s into %s, err=%v", sourceURL, archiveFullPath, err)
}

log.Debugf("Downloaded %s into %s", sourceURL, archiveFullPath)
Expand All @@ -284,7 +287,8 @@ func GetCachedArchive(siteName string, prefixString string, internalExtractionPa
if err != nil {
_ = fileutil.PurgeDirectory(extractPath)
_ = os.RemoveAll(extractPath)
return "", "", fmt.Errorf("archive extraction of %s failed err=%v", archiveFullPath, err)
_ = os.RemoveAll(archiveFullPath)
return extractPath, archiveFullPath, fmt.Errorf("archive extraction of %s failed err=%v", archiveFullPath, err)
}
return extractPath, archiveFullPath, nil
}
38 changes: 17 additions & 21 deletions pkg/testcommon/testcommon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,24 @@ func TestValidTestSite(t *testing.T) {

}

// TestInvalidTestSite ensures that errors are returned in cases where Prepare() can't download or extract an archive.
func TestInvalidTestSite(t *testing.T) {
// TestGetCachedArchive tests download and extraction of archives for test sites
// to testcache directory.
func TestGetCachedArchive(t *testing.T) {
assert := asrt.New(t)

testSites := []TestSite{
// This should generate a 404 page on github, which will be downloaded, but cannot be extracted (as it's not a true tar.gz)
{
Name: "TestInvalidTestSite404",
SourceURL: "https://github.com/drud/drupal8/archive/somevaluethatdoesnotexist.tar.gz",
},
// This is an invalid domain, so it can't even be downloaded. This tests error handling in the case of
// a site URL which does not exist
{
Name: "TestInvalidTestSiteInvalidDomain",
SourceURL: "http://invalid_domain/somefilethatdoesnotexists",
},
}
sourceURL := "https://raw.githubusercontent.com/drud/ddev/master/.gitignore"
exPath, archPath, err := GetCachedArchive("TestInvalidArchive", "test", "", sourceURL)
assert.Error(err)
assert.Contains(err.Error(), fmt.Sprintf("archive extraction of %s failed", archPath))

for i := range testSites {
ts := testSites[i]
// Create a testsite and ensure the prepare() method extracts files into a temporary directory.
err := ts.Prepare()
assert.Error(err, "ts.Prepare() fails because of missing config.yml or untar failure")
}
err = os.RemoveAll(filepath.Dir(exPath))
assert.NoError(err)

sourceURL = "http://invalid_domain/somefilethatdoesnotexists"
exPath, archPath, err = GetCachedArchive("TestInvalidDownloadURL", "test", "", sourceURL)
assert.Error(err)
assert.Contains(err.Error(), fmt.Sprintf("Failed to download url=%s into %s", sourceURL, archPath))

err = os.RemoveAll(filepath.Dir(exPath))
assert.NoError(err)
}

0 comments on commit fd5b699

Please sign in to comment.