diff --git a/.travis.yml b/.travis.yml index 0bf01adf..53031927 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: - linux go: - - 1.13.x + - 1.15.x # use containers which run faster and have cache sudo: false diff --git a/README.md b/README.md index eed7e4f4..f69d1236 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Head to the [releases](https://github.com/zaquestion/lab/releases) page and down ### Source Required -* [Go 1.13+](https://golang.org/doc/install) +* [Go 1.15+](https://golang.org/doc/install) ``` git clone git@github.com:zaquestion/lab diff --git a/internal/config/config.go b/internal/config/config.go index 8fb699db..ec292841 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -100,13 +100,11 @@ func ConvertHCLtoTOML(oldpath string, newpath string, file string) { oldconfig := oldpath + "/" + file + ".hcl" newconfig := newpath + "/" + file + ".toml" - _, err := os.Stat(oldconfig) - if os.IsNotExist(err) { + if _, err := os.Stat(oldconfig); os.IsNotExist(err) { return } - _, err = os.Stat(newconfig) - if err == nil { + if _, err := os.Stat(newconfig); err == nil { return } @@ -120,8 +118,7 @@ func ConvertHCLtoTOML(oldpath string, newpath string, file string) { viper.WriteConfigAs(newconfig) // delete the old config HCL file - err = os.Remove(oldconfig) - if err != nil { + if err := os.Remove(oldconfig); err != nil { fmt.Println("Warning: Could not delete old config file", oldconfig) } @@ -193,8 +190,8 @@ func LoadConfig() (string, string, string, string, bool) { // Convert old hcl files to toml format. // NO NEW FILES SHOULD BE ADDED BELOW. - ConvertHCLtoTOML(".", ".", "lab") ConvertHCLtoTOML(confpath, labconfpath, "lab") + ConvertHCLtoTOML(".", ".", "lab") var labgitDir string gitDir, err := git.GitDir() if err == nil { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index d90d7402..3556d457 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path" + "path/filepath" "strings" "testing" @@ -16,10 +17,7 @@ import ( ) func TestNewConfig(t *testing.T) { - testconf, err := ioutil.TempDir("", "testconf-") - if err != nil { - t.Fatal(err) - } + testconf := t.TempDir() t.Run("create config", func(t *testing.T) { old := os.Stdout // keep backup of the real stdout @@ -73,15 +71,11 @@ func TestNewConfig(t *testing.T) { token = "abcde12345" `, string(cfgData)) }) - os.RemoveAll(testconf) viper.Reset() } func TestNewConfigHostOverride(t *testing.T) { - testconf, err := ioutil.TempDir("", "testconf-") - if err != nil { - t.Fatal(err) - } + testconf := t.TempDir() os.Setenv("LAB_CORE_HOST", "https://gitlab2.zaquestion.io") @@ -141,6 +135,44 @@ func TestNewConfigHostOverride(t *testing.T) { token = "abcde12345" `, string(cfgData)) }) - os.RemoveAll(testconf) viper.Reset() } + +func TestConvertHCLtoTOML(t *testing.T) { + tmpDir := t.TempDir() + oldCnfPath := filepath.Join(tmpDir, "lab.hcl") + newCnfPath := filepath.Join(tmpDir, "lab.toml") + oldCnf, err := os.Create(oldCnfPath) + if err != nil { + t.Fatal(err) + } + oldCnf.WriteString(`"core" = { + "host" = "https://gitlab.com" + "token" = "foobar" + "user" = "lab-testing" +}`) + + ConvertHCLtoTOML(tmpDir, tmpDir, "lab") + + _, err = os.Stat(oldCnfPath) + assert.True(t, os.IsNotExist(err)) + + _, err = os.Stat(newCnfPath) + assert.NoError(t, err) + + newCnf, err := os.Open(newCnfPath) + if err != nil { + t.Fatal(err) + } + cfgData, err := ioutil.ReadAll(newCnf) + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, ` +[core] + host = "https://gitlab.com" + token = "foobar" + user = "lab-testing" +`, string(cfgData)) +}