Beispiel #1
0
func init() {
	// These are well known restricted IAM keys to a HashiCorp-managed bucket
	// in a private AWS account that only has access to the open source test
	// resources.
	os.Setenv("AWS_ACCESS_KEY", "AKIAJCTNQIOBWAYXKGZA")
	os.Setenv("AWS_SECRET_KEY", "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")
}
func TestApplicationFooter(t *testing.T) {
	testcases := []footerTestcase{
		{"", "", "", "", "",
			"[" + brandName + " local]"},
		{"susen-staging-pr-30",
			"v29",
			"",
			"ca0fd7123f918d1b6d3e65f3de47d52db09ae068",
			"dev",
			"[susen-staging-pr-30 CI/CD]"},
		{"susen-staging",
			"v29",
			"1vac4117-c29f-4312-521e-ba4d8638c1ac",
			"ca0fd7123f918d1b6d3e65f3de47d52db09ae068",
			"stg",
			"[susen-staging v29 <ca0fd71>]"},
		{"susen-production",
			"v22",
			"1vac4117-c29f-4312-521e-ba4d8638c1ac",
			"ca0fd7123f918d1b6d3e65f3de47d52db09ae068",
			"prd",
			"[susen-production v22 <ca0fd71> (dyno 1vac4117-c29f-4312-521e-ba4d8638c1ac)]"},
	}
	for i, tc := range testcases {
		os.Setenv(applicationNameEnvVar, tc.name)
		os.Setenv(applicationVersionEnvVar, tc.version)
		os.Setenv(applicationInstanceEnvVar, tc.instance)
		os.Setenv(applicationBuildEnvVar, tc.build)
		os.Setenv(applicationEnvEnvVar, tc.env)
		if footer := applicationFooter(); footer != tc.footer {
			t.Errorf("Case %d: got %q, expected %q", i, footer, tc.footer)
		}
	}
}
Beispiel #3
0
func TestDriverSetFromEnvironmentVariable(t *testing.T) {

	databaseUrlEnvVariableKey := "DB_DRIVER"
	databaseUrlEnvVariableVal := "sqlite3"
	databaseOpenStringKey := "DATABASE_URL"
	databaseOpenStringVal := "db.db"

	os.Setenv(databaseUrlEnvVariableKey, databaseUrlEnvVariableVal)
	os.Setenv(databaseOpenStringKey, databaseOpenStringVal)

	dbconf, err := NewDBConf("../../_example", "environment_variable_config", "")
	if err != nil {
		t.Fatal(err)
	}

	got := reflect.TypeOf(dbconf.Driver.Dialect)
	want := reflect.TypeOf(&Sqlite3Dialect{})

	if got != want {
		t.Errorf("Not able to read the driver type from environment variable."+
			"got %v want %v", got, want)
	}

	gotOpenString := dbconf.Driver.OpenStr
	wantOpenString := databaseOpenStringVal

	if gotOpenString != wantOpenString {
		t.Errorf("Not able to read the open string from the environment."+
			"got %v want %v", gotOpenString, wantOpenString)
	}
}
Beispiel #4
0
func TestInvalidBool(t *testing.T) {
	os.Setenv("othervar", "should-be-a-bool")
	defer os.Setenv("othervar", "")

	cfg := Config{}
	assert.Error(t, env.Parse(&cfg))
}
Beispiel #5
0
// Test the primary path: creating an app on a `convox` rack
// Return to testing against a `convox-test` rack afterwards
func TestAppCreate(t *testing.T) {
	r := os.Getenv("RACK")
	os.Setenv("RACK", "convox")
	defer os.Setenv("RACK", r)

	aws := test.StubAws(
		test.DescribeStackNotFound("application"),
		test.CreateAppStackCycle("convox-application"),
		test.DescribeAppStackCycle("convox-application"),
	)
	defer aws.Close()

	val := url.Values{"name": []string{"application"}}
	body := test.HTTPBody("POST", "http://convox/apps", val)

	if assert.NotEqual(t, "", body) {
		var resp map[string]string
		err := json.Unmarshal([]byte(body), &resp)

		if assert.Nil(t, err) {
			assert.Equal(t, "application", resp["name"])
			assert.Equal(t, "running", resp["status"])
		}
	}
}
func TestNewDNSProviderRoute53ValidEnv(t *testing.T) {
	os.Setenv("AWS_ACCESS_KEY_ID", "123")
	os.Setenv("AWS_SECRET_ACCESS_KEY", "123")
	_, err := NewDNSProviderRoute53("", "", "us-east-1")
	assert.NoError(t, err)
	restoreRoute53Env()
}
Beispiel #7
0
func TestConfig(t *testing.T) {
	wd, _ := os.Getwd()

	Convey("The Config Builders", t, func() {
		conf := DefaultConfig()

		Convey("ReadConfigFile", func() {
			ReadConfigFile(conf, fmt.Sprintf("%s/config_test.yml", wd))
			So(conf.Port, ShouldEqual, 8080)
			So(conf.Address, ShouldEqual, "0.0.0.0")
			So(conf.CredentialsFile, ShouldEqual, "/tmp/secret_file")
		})

		Convey("ReadEnvironment", func() {
			master := "zk://local.host:2182/mesos"
			dbPath := "db/eremetic.db"
			frameworkID := "a_framework_id"

			os.Setenv("MASTER", master)
			os.Setenv("DATABASE", dbPath)
			os.Setenv("FRAMEWORK_ID", frameworkID)

			ReadEnvironment(conf)

			So(conf.Master, ShouldEqual, master)
			So(conf.DatabasePath, ShouldEqual, dbPath)
			So(conf.FrameworkID, ShouldEqual, frameworkID)
		})
	})
}
Beispiel #8
0
func (*CmdSuite) TestDeployCommandInit(c *C) {
	defer os.Setenv("JUJU_REPOSITORY", os.Getenv("JUJU_REPOSITORY"))
	os.Setenv("JUJU_REPOSITORY", "/path/to/repo")

	for _, t := range deployTests {
		initExpectations(t.com)
		com, err := initDeployCommand(t.args...)
		c.Assert(err, IsNil)
		c.Assert(com, DeepEquals, t.com)
	}

	// test relative --config path
	ctx := coretesting.Context(c)
	expected := []byte("test: data")
	path := ctx.AbsPath("testconfig.yaml")
	file, err := os.Create(path)
	c.Assert(err, IsNil)
	_, err = file.Write(expected)
	c.Assert(err, IsNil)
	file.Close()

	com, err := initDeployCommand("--config", "testconfig.yaml", "charm-name")
	c.Assert(err, IsNil)
	actual, err := com.Config.Read(ctx)
	c.Assert(err, IsNil)
	c.Assert(expected, DeepEquals, actual)

	// missing args
	_, err = initDeployCommand()
	c.Assert(err, ErrorMatches, "no charm specified")

	// environment tested elsewhere
}
Beispiel #9
0
// TestEnvironmentInit tests that all commands which accept
// the --environment variable initialise their
// environment name correctly.
func (*CmdSuite) TestEnvironmentInit(c *C) {
	for i, cmdFunc := range EnvironmentInitTests {
		c.Logf("test %d", i)
		com, args := cmdFunc()
		testInit(c, com, args, "")
		assertConnName(c, com, "")

		com, args = cmdFunc()
		testInit(c, com, append(args, "-e", "walthamstow"), "")
		assertConnName(c, com, "walthamstow")

		com, args = cmdFunc()
		testInit(c, com, append(args, "--environment", "walthamstow"), "")
		assertConnName(c, com, "walthamstow")

		// JUJU_ENV is the final place the environment can be overriden
		com, args = cmdFunc()
		oldenv := os.Getenv("JUJU_ENV")
		os.Setenv("JUJU_ENV", "walthamstow")
		testInit(c, com, args, "")
		os.Setenv("JUJU_ENV", oldenv)
		assertConnName(c, com, "walthamstow")

		com, args = cmdFunc()
		testInit(c, com, append(args, "hotdog"), "unrecognized args.*")
	}
}
func TestAlternateVarNames(t *testing.T) {
	var s Specification
	os.Clearenv()
	os.Setenv("ENV_CONFIG_MULTI_WORD_VAR", "foo")
	os.Setenv("ENV_CONFIG_MULTI_WORD_VAR_WITH_ALT", "bar")
	os.Setenv("ENV_CONFIG_MULTI_WORD_VAR_WITH_LOWER_CASE_ALT", "baz")
	if err := Process("env_config", &s); err != nil {
		t.Error(err.Error())
	}

	// Setting the alt version of the var in the environment has no effect if
	// the struct tag is not supplied
	if s.MultiWordVar != "" {
		t.Errorf("expected %q, got %q", "", s.MultiWordVar)
	}

	// Setting the alt version of the var in the environment correctly sets
	// the value if the struct tag IS supplied
	if s.MultiWordVarWithAlt != "bar" {
		t.Errorf("expected %q, got %q", "bar", s.MultiWordVarWithAlt)
	}

	// Alt value is not case sensitive and is treated as all uppercase
	if s.MultiWordVarWithLowerCaseAlt != "baz" {
		t.Errorf("expected %q, got %q", "baz", s.MultiWordVarWithLowerCaseAlt)
	}
}
func TestProcess(t *testing.T) {
	var s Specification
	os.Clearenv()
	os.Setenv("ENV_CONFIG_DEBUG", "true")
	os.Setenv("ENV_CONFIG_PORT", "8080")
	os.Setenv("ENV_CONFIG_RATE", "0.5")
	os.Setenv("ENV_CONFIG_USER", "Kelsey")
	os.Setenv("SERVICE_HOST", "127.0.0.1")
	err := Process("env_config", &s)
	if err != nil {
		t.Error(err.Error())
	}
	if s.NoPrefixWithAlt != "127.0.0.1" {
		t.Errorf("expected %v, got %v", "127.0.0.1", s.NoPrefixWithAlt)
	}
	if !s.Debug {
		t.Errorf("expected %v, got %v", true, s.Debug)
	}
	if s.Port != 8080 {
		t.Errorf("expected %d, got %v", 8080, s.Port)
	}
	if s.Rate != 0.5 {
		t.Errorf("expected %f, got %v", 0.5, s.Rate)
	}
	if s.User != "Kelsey" {
		t.Errorf("expected %s, got %s", "Kelsey", s.User)
	}
}
Beispiel #12
0
func TestFindAppDir(t *testing.T) {
	tempDir, err := ioutil.TempDir("", "TestFindAppDir")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tempDir)
	origGOPATH := build.Default.GOPATH
	defer func() {
		build.Default.GOPATH = origGOPATH
		os.Setenv("GOPATH", origGOPATH)
	}()
	build.Default.GOPATH = tempDir + string(filepath.ListSeparator) + build.Default.GOPATH
	os.Setenv("GOPATH", build.Default.GOPATH)
	myappPath := filepath.Join(tempDir, "src", "path", "to", "myapp")
	if err := os.MkdirAll(myappPath, 0755); err != nil {
		t.Fatal(err)
	}
	if err := os.Chdir(myappPath); err != nil {
		t.Fatal(err)
	}
	actual, err := FindAppDir()
	if err != nil {
		t.Fatal(err)
	}
	expected := "path/to/myapp"
	if !reflect.DeepEqual(actual, expected) {
		t.Errorf("FindAppDir() => %q, want %q", actual, expected)
	}
}
Beispiel #13
0
func TestCreateAccount(t *testing.T) {
	os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com")
	defer os.Setenv("DOCKER_INDEX_URL", "")
	tokenBuffer := make([]byte, 16)
	_, err := rand.Read(tokenBuffer)
	if err != nil {
		t.Fatal(err)
	}
	token := hex.EncodeToString(tokenBuffer)[:12]
	username := "******" + token
	authConfig := &AuthConfig{Username: username, Password: "******", Email: "docker-ut+" + token + "@example.com"}
	status, err := Login(authConfig, nil)
	if err != nil {
		t.Fatal(err)
	}
	expectedStatus := "Account created. Please use the confirmation link we sent" +
		" to your e-mail to activate it."
	if status != expectedStatus {
		t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status)
	}

	status, err = Login(authConfig, nil)
	if err == nil {
		t.Fatalf("Expected error but found nil instead")
	}

	expectedError := "Login: Account is not Active"

	if !strings.Contains(err.Error(), expectedError) {
		t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err)
	}
}
Beispiel #14
0
func TestNamespaceResetting(t *testing.T) {
	// These environment variables are necessary because *Query.Run will
	// call internal.FullyQualifiedAppID which checks these variables or falls
	// back to the Metadata service that is not available in tests.
	environ := []struct {
		key, value string
	}{
		{"GAE_LONG_APP_ID", "my-app-id"},
		{"GAE_PARTITION", "1"},
	}
	for _, v := range environ {
		old := os.Getenv(v.key)
		os.Setenv(v.key, v.value)
		v.value = old
	}
	defer func() { // Restore old environment after the test completes.
		for _, v := range environ {
			if v.value == "" {
				os.Unsetenv(v.key)
				continue
			}
			os.Setenv(v.key, v.value)
		}
	}()

	namec := make(chan *string, 1)
	c0 := aetesting.FakeSingleContext(t, "datastore_v3", "RunQuery", func(req *pb.Query, res *pb.QueryResult) error {
		namec <- req.NameSpace
		return fmt.Errorf("RPC error")
	})

	// Check that wrapping c0 in a namespace twice works correctly.
	c1, err := appengine.Namespace(c0, "A")
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}
	c2, err := appengine.Namespace(c1, "") // should act as the original context
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}

	q := NewQuery("SomeKind")

	q.Run(c0)
	if ns := <-namec; ns != nil {
		t.Errorf(`RunQuery with c0: ns = %q, want nil`, *ns)
	}

	q.Run(c1)
	if ns := <-namec; ns == nil {
		t.Error(`RunQuery with c1: ns = nil, want "A"`)
	} else if *ns != "A" {
		t.Errorf(`RunQuery with c1: ns = %q, want "A"`, *ns)
	}

	q.Run(c2)
	if ns := <-namec; ns != nil {
		t.Errorf(`RunQuery with c2: ns = %q, want nil`, *ns)
	}
}
Beispiel #15
0
func TestStepTempDir_notmpdir(t *testing.T) {
	tempenv := "TMPDIR"
	if runtime.GOOS == "windows" {
		tempenv = "TMP"
	}
	// Verify empty TMPDIR maps to current working directory
	oldenv := os.Getenv(tempenv)
	os.Setenv(tempenv, "")
	defer os.Setenv(tempenv, oldenv)

	dir1 := testStepTempDir_impl(t)

	// Now set TMPDIR to current directory
	abspath, err := filepath.Abs(".")
	if err != nil {
		t.Fatalf("could not get current working directory")
	}
	os.Setenv(tempenv, abspath)

	dir2 := testStepTempDir_impl(t)

	if filepath.Dir(dir1) != filepath.Dir(dir2) {
		t.Fatalf("temp base directories do not match: %s %s", filepath.Dir(dir1), filepath.Dir(dir2))
	}
}
Beispiel #16
0
func TestClient_vaauthorize_env(t *testing.T) {

	os.Setenv("VCLOUDAIR_USERNAME", "username")
	os.Setenv("VCLOUDAIR_PASSWORD", "password")

	testServer.Start()
	var err error
	os.Setenv("VCLOUDAIR_ENDPOINT", "http://localhost:4444/api")
	client, err := NewClient()
	if err != nil {
		t.Fatalf("err: %v", err)
	}

	testServer.Response(201, authheader, vaauthorization)
	_, err = client.vaauthorize("", "")
	_ = testServer.WaitRequest()
	if err != nil {
		t.Fatalf("err: %v", err)
	}

	if client.VAToken != "012345678901234567890123456789" {
		t.Fatalf("VAtoken not set on client: %s", client.VAToken)
	}

}
func TestNewDNSProviderRoute53MissingAuthErr(t *testing.T) {
	os.Setenv("AWS_ACCESS_KEY_ID", "")
	os.Setenv("AWS_SECRET_ACCESS_KEY", "")
	_, err := NewDNSProviderRoute53("", "", "us-east-1")
	assert.EqualError(t, err, "AWS credentials missing")
	restoreRoute53Env()
}
Beispiel #18
0
func TestClient_vaacquireservice_env(t *testing.T) {

	os.Setenv("VCLOUDAIR_COMPUTEID", "CI123456-789")

	testServer.Start()
	var err error
	os.Setenv("VCLOUDAIR_ENDPOINT", "http://localhost:4444/api")
	client, err := NewClient()
	if err != nil {
		t.Fatalf("err: %v", err)
	}
	client.VAToken = "012345678901234567890123456789"

	testServer.Response(200, nil, vaservices)
	vacomputehref, err := client.vaacquireservice(*aus, "")
	_ = testServer.WaitRequest()
	if err != nil {
		t.Fatalf("err: %v", err)
	}

	if vacomputehref.String() != "http://localhost:4444/api/vchs/compute/00000000-0000-0000-0000-000000000000" {
		t.Fatalf("VAComputeHREF not set on client: %s", vacomputehref)
	}

	if client.Region != "US - Anywhere" {
		t.Fatalf("Region not set on client: %s", client.Region)
	}

}
Beispiel #19
0
func (e *MergeEnvSuite) TestMergeEnviron(c *gc.C) {
	// environment does not get fully cleared on Windows
	// when using testing.IsolationSuite
	origEnv := os.Environ()
	extraExpected := []string{
		"DUMMYVAR=foo",
		"DUMMYVAR2=bar",
		"NEWVAR=ImNew",
	}
	expectEnv := make([]string, 0, len(origEnv)+len(extraExpected))

	// os.Environ prepends some garbage on Windows that we need to strip out.
	// All the garbage starts and ends with = (for example "=C:=").
	for _, v := range origEnv {
		if !(strings.HasPrefix(v, "=") && strings.HasSuffix(v, "=")) {
			expectEnv = append(expectEnv, v)
		}
	}
	expectEnv = append(expectEnv, extraExpected...)
	os.Setenv("DUMMYVAR2", "ChangeMe")
	os.Setenv("DUMMYVAR", "foo")

	newEnv := make([]string, 0, len(expectEnv))
	for _, v := range runner.MergeWindowsEnvironment([]string{"dummyvar2=bar", "NEWVAR=ImNew"}, os.Environ()) {
		if !(strings.HasPrefix(v, "=") && strings.HasSuffix(v, "=")) {
			newEnv = append(newEnv, v)
		}
	}
	c.Assert(expectEnv, jc.SameContents, newEnv)
}
Beispiel #20
0
func TestClient_vaacquirecompute_env(t *testing.T) {

	os.Setenv("VCLOUDAIR_VDCID", "VDC12345-6789")

	testServer.Start()
	var err error
	os.Setenv("VCLOUDAIR_ENDPOINT", "http://localhost:4444/api")
	client, err := NewClient()
	if err != nil {
		t.Fatalf("err: %v", err)
	}
	client.VAToken = "012345678901234567890123456789"
	client.Region = "US - Anywhere"

	testServer.Response(200, nil, vacompute)
	vavdchref, err := client.vaacquirecompute(*auc, "")
	_ = testServer.WaitRequest()
	if err != nil {
		t.Fatalf("err: %v", err)
	}

	if vavdchref.String() != "http://localhost:4444/api/vchs/compute/00000000-0000-0000-0000-000000000000/vdc/00000000-0000-0000-0000-000000000000/vcloudsession" {
		t.Fatalf("VAVDCHREF not set on client: %s", vavdchref)
	}

}
Beispiel #21
0
func TestEnsurePharosConfig(t *testing.T) {
	configFile := filepath.Join("config", "test.json")
	config, err := models.LoadConfigFile(configFile)
	require.Nil(t, err)

	url := config.PharosURL
	config.PharosURL = ""
	err = config.EnsurePharosConfig()
	assert.Equal(t, "PharosUrl is missing from config file", err.Error())

	config.PharosURL = url
	apiUser := os.Getenv("PHAROS_API_USER")
	os.Setenv("PHAROS_API_USER", "")
	err = config.EnsurePharosConfig()
	assert.Equal(t, "Environment variable PHAROS_API_USER is not set", err.Error())

	os.Setenv("PHAROS_API_USER", "Bogus value set by config_test.go")
	apiKey := os.Getenv("PHAROS_API_KEY")
	os.Setenv("PHAROS_API_KEY", "")
	err = config.EnsurePharosConfig()
	assert.Equal(t, "Environment variable PHAROS_API_KEY is not set", err.Error())

	os.Setenv("PHAROS_API_USER", apiUser)
	os.Setenv("PHAROS_API_KEY", apiKey)
}
Beispiel #22
0
func TestClient_vagetbackendauth_env(t *testing.T) {

	os.Setenv("VCLOUDAIR_VDCID", "VDC12345-6789")

	testServer.Start()
	var err error
	os.Setenv("VCLOUDAIR_ENDPOINT", "http://localhost:4444/api")
	client, err := NewClient()
	if err != nil {
		t.Fatalf("err: %v", err)
	}
	client.VAToken = "012345678901234567890123456789"
	client.Region = "US - Anywhere"

	testServer.Response(201, nil, vabackend)
	err = client.vagetbackendauth(*aucs, "")
	_ = testServer.WaitRequest()
	if err != nil {
		t.Fatalf("err: %v", err)
	}

	if client.VCDToken != "01234567890123456789012345678901" {
		t.Fatalf("VCDToken not set on client: %s", client.VCDToken)
	}
	if client.VCDAuthHeader != "x-vcloud-authorization" {
		t.Fatalf("VCDAuthHeader not set on client: %s", client.VCDAuthHeader)
	}
	if client.VCDVDCHREF.String() != "http://localhost:4444/api/vdc/00000000-0000-0000-0000-000000000000" {
		t.Fatalf("VDC not set on client: %s", client.VCDVDCHREF)
	}

}
Beispiel #23
0
func TestInvalidInt(t *testing.T) {
	os.Setenv("PORT", "should-be-an-int")
	defer os.Setenv("PORT", "")

	cfg := Config{}
	assert.Error(t, env.Parse(&cfg))
}
Beispiel #24
0
func execCmd(gopath, curPath string, args ...string) error {
	oldGopath := os.Getenv("GOPATH")
	log.Info("Setting GOPATH to %s", gopath)

	sep := ":"
	if runtime.GOOS == "windows" {
		sep = ";"
	}

	if err := os.Setenv("GOPATH", gopath+sep+oldGopath); err != nil {
		if setting.LibraryMode {
			return fmt.Errorf("Fail to setting GOPATH: %v", err)
		}
		log.Error("", "Fail to setting GOPATH:")
		log.Fatal("", "\t"+err.Error())
	}
	if setting.HasGOPATHSetting {
		defer func() {
			log.Info("Setting GOPATH back to %s", oldGopath)
			os.Setenv("GOPATH", oldGopath)
		}()
	}

	cmd := exec.Command(args[0], args[1:]...)
	cmd.Dir = curPath
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	log.Info("===== application outputs start =====\n")

	err := cmd.Run()

	log.Info("====== application outputs end ======")
	return err
}
Beispiel #25
0
// SetEnv stores keys as environment vars
func (k *Keys) SetEnv() {
	err := os.Setenv("AWS_ACCESS_KEY", k.AccessKey)
	err = os.Setenv("AWS_SECRET_KEY", k.SecretKey)
	if err != nil {
		log.Fatalln("Failed to set environment vars")
	}
}
func TestParse_Global(t *testing.T) {
	resetForTesting("")

	os.Setenv(envTestPrefix+"D", "EnvD")
	os.Setenv(envTestPrefix+"E", "true")
	os.Setenv(envTestPrefix+"F", "5.5")

	flagA := flag.Bool("a", false, "")
	flagB := flag.Float64("b", 0.0, "")
	flagC := flag.String("c", "", "")

	flagD := flag.String("d", "", "")
	flagE := flag.Bool("e", false, "")
	flagF := flag.Float64("f", 0.0, "")

	parse(t, "./testdata/global.ini", envTestPrefix)
	if !*flagA {
		t.Errorf("flagA found %v, expected true", *flagA)
	}
	if *flagB != 5.6 {
		t.Errorf("flagB found %v, expected 5.6", *flagB)
	}
	if *flagC != "Hello world" {
		t.Errorf("flagC found %v, expected 'Hello world'", *flagC)
	}
	if *flagD != "EnvD" {
		t.Errorf("flagD found %v, expected 'EnvD'", *flagD)
	}
	if !*flagE {
		t.Errorf("flagE found %v, expected true", *flagE)
	}
	if *flagF != 5.5 {
		t.Errorf("flagF found %v, expected 5.5", *flagF)
	}
}
Beispiel #27
0
func (s *ConfigSuite) TearDownTest(c *gc.C) {
	utils.SetHome(s.savedHome)
	os.Setenv("AWS_ACCESS_KEY_ID", s.savedAccessKey)
	os.Setenv("AWS_SECRET_ACCESS_KEY", s.savedSecretKey)
	delete(aws.Regions, "configtest")
	s.BaseSuite.TearDownTest(c)
}
Beispiel #28
0
func TestEnvLOGXI_FORMAT(t *testing.T) {
	assert := assert.New(t)
	oldIsTerminal := isTerminal

	os.Setenv("LOGXI_FORMAT", "")
	setDefaults(true)
	processEnv()
	assert.Equal(FormatHappy, logxiFormat, "terminal defaults to FormatHappy")
	setDefaults(false)
	processEnv()
	assert.Equal(FormatJSON, logxiFormat, "non terminal defaults to FormatJSON")

	os.Setenv("LOGXI_FORMAT", "JSON")
	processEnv()
	assert.Equal(FormatJSON, logxiFormat)

	os.Setenv("LOGXI_FORMAT", "json")
	setDefaults(true)
	processEnv()
	assert.Equal(FormatHappy, logxiFormat, "Mismatches defaults to FormatHappy")
	setDefaults(false)
	processEnv()
	assert.Equal(FormatJSON, logxiFormat, "Mismatches defaults to FormatJSON non terminal")

	isTerminal = oldIsTerminal
	setDefaults(isTerminal)
}
Beispiel #29
0
func (n *Node) DownloadByGoGet(ctx *cli.Context, u *url.URL) error {
	baseDir := path.Join(setting.HomeDir, ".gopm/temp/goget")
	os.MkdirAll(baseDir, os.ModePerm)
	defer func() {
		os.RemoveAll(baseDir)
	}()

	oriGopath := os.Getenv("GOPATH")
	os.Setenv("GOPATH", baseDir)
	fmt.Println(baseDir)
	defer func() {
		os.Setenv("GOPATH", oriGopath)
	}()

	log.Debug("RUN 'go get %s'", n.RootPath)
	_, stderr, err := base.ExecCmdDir(baseDir, "go", "get", n.RootPath)
	if err != nil {
		log.Error("Error occurs when 'go get" + n.RootPath + "'")
		log.Error("\t" + stderr)
		return errors.New(stderr)
	}
	tmpPath := path.Join(baseDir, "src", n.RootPath)
	if !n.IsEmptyVal() {
		base.ExecCmdDir(tmpPath, "git", "checkout", n.Value)
		if err != nil {
			log.Error("Error occurs when 'git checkout" + n.Value + "'")
			log.Error("\t" + stderr)
			return errors.New(stderr)
		}
	}
	os.MkdirAll(path.Dir(n.InstallPath), os.ModePerm)
	os.Rename(tmpPath, n.InstallPath)
	return nil
}
Beispiel #30
0
func TestEnsurePrereqs(t *testing.T) {
	pp := os.Getenv("PATH")
	defer os.Setenv("PATH", pp)
	here, _ := os.Getwd()
	os.Setenv("PATH", filepath.Join(here, "../testdata")+":"+pp)
	ensurePrereqs()
}