github.com/chasestarr/deis@v1.13.5-0.20170519182049-1d9e59fbdbfc/tests/domains_test.go (about)

     1  // +build integration
     2  
     3  package tests
     4  
     5  import (
     6  	"fmt"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/deis/deis/tests/utils"
    11  )
    12  
    13  var (
    14  	certsAddCmd      = "certs:add {{.SSLCertificatePath}} {{.SSLKeyPath}}"
    15  	certsRemoveCmd   = "certs:remove {{.AppDomain}}"
    16  	domainsAddCmd    = "domains:add {{.AppDomain}} --app {{.AppName}}"
    17  	domainsRemoveCmd = "domains:remove {{.AppDomain}} --app {{.AppName}}"
    18  )
    19  
    20  func TestDomains(t *testing.T) {
    21  	cfg := domainsSetup(t)
    22  	domainsTest(t, cfg)
    23  	certsTest(t, cfg)
    24  	utils.AppsDestroyTest(t, cfg)
    25  }
    26  
    27  func domainsSetup(t *testing.T) *utils.DeisTestConfig {
    28  	cfg := utils.GetGlobalConfig()
    29  	cfg.AppName = "domainsample"
    30  	utils.Execute(t, authLoginCmd, cfg, false, "")
    31  	utils.Execute(t, gitCloneCmd, cfg, false, "")
    32  	if err := utils.Chdir(cfg.ExampleApp); err != nil {
    33  		t.Fatal(err)
    34  	}
    35  	utils.Execute(t, appsCreateCmd, cfg, false, "")
    36  	utils.Execute(t, gitPushCmd, cfg, false, "")
    37  	utils.CurlApp(t, *cfg)
    38  	if err := utils.Chdir(".."); err != nil {
    39  		t.Fatal(err)
    40  	}
    41  	return cfg
    42  }
    43  
    44  func domainsTest(t *testing.T, cfg *utils.DeisTestConfig) {
    45  	utils.Execute(t, domainsAddCmd, cfg, false, "done")
    46  	// ensure both the root domain and the custom domain work
    47  	utils.CurlApp(t, *cfg)
    48  	utils.Curl(t, fmt.Sprintf("http://%s", cfg.AppDomain))
    49  	utils.Execute(t, domainsRemoveCmd, cfg, false, "done")
    50  	// only the root domain should work now
    51  	utils.CurlApp(t, *cfg)
    52  	// TODO (bacongobbler): add test to ensure that the custom domain fails to connect
    53  }
    54  
    55  func certsTest(t *testing.T, cfg *utils.DeisTestConfig) {
    56  	utils.Execute(t, domainsAddCmd, cfg, false, "done")
    57  	utils.Execute(t, certsAddCmd, cfg, false, cfg.AppDomain)
    58  	// wait for the certs to be populated in the router; cron takes up to 1 minute
    59  	fmt.Println("sleeping for 60 seconds until certs are generated...")
    60  	time.Sleep(60 * time.Second)
    61  	fmt.Println("ok")
    62  	// ensure the custom domain's SSL endpoint works
    63  	utils.Curl(t, fmt.Sprintf("https://%s", cfg.AppDomain))
    64  	utils.Execute(t, certsRemoveCmd, cfg, false, "done")
    65  	// only the root domain should work now
    66  	utils.CurlApp(t, *cfg)
    67  	// TODO (bacongobbler): add test to ensure that the custom domain fails to connect
    68  }