本文整理汇总了Golang中os.Setenv函数的典型用法代码示例。如果您正苦于以下问题:Golang Setenv函数的具体用法?Golang Setenv怎么用?Golang Setenv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Setenv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
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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")
}
示例2: TestApplicationFooter
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)
}
}
}
示例3: TestDriverSetFromEnvironmentVariable
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)
}
}
示例4: TestInvalidBool
func TestInvalidBool(t *testing.T) {
os.Setenv("othervar", "should-be-a-bool")
defer os.Setenv("othervar", "")
cfg := Config{}
assert.Error(t, env.Parse(&cfg))
}
示例5: TestAppCreate
// 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"])
}
}
}
示例6: TestNewDNSProviderRoute53ValidEnv
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()
}
示例7: TestConfig
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)
})
})
}
示例8: TestDeployCommandInit
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
}
示例9: TestEnvironmentInit
// 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.*")
}
}
示例10: TestAlternateVarNames
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)
}
}
示例11: TestProcess
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)
}
}
示例12: TestFindAppDir
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)
}
}
示例13: TestCreateAccount
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 := "ut" + token
authConfig := &AuthConfig{Username: username, Password: "test42", 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)
}
}
示例14: TestNamespaceResetting
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)
}
}
示例15: TestStepTempDir_notmpdir
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))
}
}