github.com/echohead/hub@v2.2.1+incompatible/fixtures/test_configs.go (about)

     1  package fixtures
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  )
     7  
     8  type TestConfigs struct {
     9  	Path string
    10  }
    11  
    12  func (c *TestConfigs) TearDown() {
    13  	os.Setenv("HUB_CONFIG", "")
    14  	os.RemoveAll(c.Path)
    15  }
    16  
    17  func SetupTomlTestConfig() *TestConfigs {
    18  	file, _ := ioutil.TempFile("", "test-gh-config-")
    19  
    20  	content := `[[hosts]]
    21    host = "github.com"
    22    user = "jingweno"
    23    access_token = "123"
    24    protocol = "http"`
    25  	ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
    26  	os.Setenv("HUB_CONFIG", file.Name())
    27  
    28  	return &TestConfigs{file.Name()}
    29  }
    30  
    31  func SetupTestConfigs() *TestConfigs {
    32  	file, _ := ioutil.TempFile("", "test-gh-config-")
    33  
    34  	content := `---
    35  github.com:
    36  - user: jingweno
    37    oauth_token: 123
    38    protocol: http`
    39  	ioutil.WriteFile(file.Name(), []byte(content), os.ModePerm)
    40  	os.Setenv("HUB_CONFIG", file.Name())
    41  
    42  	return &TestConfigs{file.Name()}
    43  }