github.com/miketheprogrammer/deis@v1.12.2/tests/config_test.go (about)

     1  // +build integration
     2  
     3  package tests
     4  
     5  import (
     6  	"io/ioutil"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/deis/deis/tests/utils"
    11  )
    12  
    13  var (
    14  	configListCmd = "config:list --app={{.AppName}}"
    15  	configSetCmd  = "config:set FOO=讲台 --app={{.AppName}}"
    16  	configSet2Cmd = "config:set FOO=10 --app={{.AppName}}"
    17  	configSet3Cmd = "config:set POWERED_BY=\"the Deis team\" --app={{.AppName}}"
    18  	configSet4Cmd = `config:set FOO="This is a
    19  multiline string" --app={{.AppName}}`
    20  	configSetBuildpackCmd = "config:set BUILDPACK_URL=$BUILDPACK_URL --app={{.AppName}}"
    21  	configUnsetCmd        = "config:unset FOO --app={{.AppName}}"
    22  )
    23  
    24  var buildpacks = map[string]string{
    25  	"example-clojure-ring":   "https://github.com/heroku/heroku-buildpack-clojure#v66",
    26  	"example-go":             "https://github.com/heroku/heroku-buildpack-go#6eeb09f",
    27  	"example-java-jetty":     "https://github.com/heroku/heroku-buildpack-java#v38",
    28  	"example-nodejs-express": "https://github.com/heroku/heroku-buildpack-nodejs#v75",
    29  	"example-perl":           "https://github.com/miyagawa/heroku-buildpack-perl#2da7480",
    30  	"example-php":            "https://github.com/heroku/heroku-buildpack-php#v67",
    31  	"example-play":           "https://github.com/heroku/heroku-buildpack-play#v23",
    32  	"example-python-django":  "https://github.com/heroku/heroku-buildpack-python#v58",
    33  	"example-python-flask":   "https://github.com/heroku/heroku-buildpack-python#v58",
    34  	"example-ruby-sinatra":   "https://github.com/heroku/heroku-buildpack-ruby#v137",
    35  	"example-scala":          "https://github.com/heroku/heroku-buildpack-scala#v55",
    36  }
    37  
    38  func TestConfig(t *testing.T) {
    39  	params := configSetup(t)
    40  	configSetTest(t, params)
    41  	configPushTest(t, params)
    42  	configListTest(t, params, false)
    43  	appsOpenTest(t, params)
    44  	configUnsetTest(t, params)
    45  	configListTest(t, params, true)
    46  	limitsSetTest(t, params, 4)
    47  	appsOpenTest(t, params)
    48  	limitsUnsetTest(t, params, 6)
    49  	appsOpenTest(t, params)
    50  	//tagsTest(t, params, 8)
    51  	appsOpenTest(t, params)
    52  	utils.AppsDestroyTest(t, params)
    53  }
    54  
    55  func configSetup(t *testing.T) *utils.DeisTestConfig {
    56  	cfg := utils.GetGlobalConfig()
    57  	cfg.AppName = "configsample"
    58  	utils.Execute(t, authLoginCmd, cfg, false, "")
    59  	utils.Execute(t, gitCloneCmd, cfg, false, "")
    60  	if err := utils.Chdir(cfg.ExampleApp); err != nil {
    61  		t.Fatal(err)
    62  	}
    63  	utils.Execute(t, appsCreateCmd, cfg, false, "")
    64  	// ensure envvars with spaces work fine on `git push`
    65  	// https://github.com/deis/deis/issues/2477
    66  	utils.Execute(t, configSet3Cmd, cfg, false, "the Deis team")
    67  	// ensure custom buildpack URLs are in order
    68  	url := buildpacks[cfg.ExampleApp]
    69  	if url == "" {
    70  		// set url anyway so example-dockerfile apps create a build
    71  		url = buildpacks["example-go"]
    72  	}
    73  	cmd := strings.Replace(configSetBuildpackCmd, "$BUILDPACK_URL", url, 1)
    74  	utils.Execute(t, cmd, cfg, false, url)
    75  	utils.Execute(t, gitPushCmd, cfg, false, "")
    76  	utils.CurlApp(t, *cfg)
    77  	utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_APP", false)
    78  	utils.CheckList(t, "run env --app={{.AppName}}", cfg, "DEIS_RELEASE", false)
    79  	if err := utils.Chdir(".."); err != nil {
    80  		t.Fatal(err)
    81  	}
    82  	return cfg
    83  }
    84  
    85  func configListTest(
    86  	t *testing.T, params *utils.DeisTestConfig, notflag bool) {
    87  	utils.CheckList(t, configListCmd, params, "FOO", notflag)
    88  }
    89  
    90  func configSetTest(t *testing.T, params *utils.DeisTestConfig) {
    91  	utils.Execute(t, configSetCmd, params, false, "讲台")
    92  	utils.CheckList(t, appsInfoCmd, params, "(v5)", false)
    93  	utils.Execute(t, configSet2Cmd, params, false, "10")
    94  	utils.CheckList(t, appsInfoCmd, params, "(v6)", false)
    95  	utils.Execute(t, configSet4Cmd, params, false, "")
    96  	utils.CheckList(t, appsInfoCmd, params, "(v7)", false)
    97  }
    98  
    99  func configPushTest(t *testing.T, params *utils.DeisTestConfig) {
   100  	if err := utils.Chdir(params.ExampleApp); err != nil {
   101  		t.Fatal(err)
   102  	}
   103  	// create a .env in the project root
   104  	if err := ioutil.WriteFile(".env", []byte("POWERED_BY=Deis"), 0664); err != nil {
   105  		t.Fatal(err)
   106  	}
   107  	utils.Execute(t, "config:push --app {{.AppName}}", params, false, "Deis")
   108  	utils.CheckList(t, appsInfoCmd, params, "(v8)", false)
   109  	if err := utils.Chdir(".."); err != nil {
   110  		t.Fatal(err)
   111  	}
   112  }
   113  
   114  func configUnsetTest(t *testing.T, params *utils.DeisTestConfig) {
   115  	utils.Execute(t, configUnsetCmd, params, false, "")
   116  	utils.CheckList(t, appsInfoCmd, params, "(v9)", false)
   117  	utils.CheckList(t, "run env --app={{.AppName}}", params, "FOO", true)
   118  }