Skip to content

Commit

Permalink
config: Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vHanda committed May 19, 2022
1 parent 1fc7b92 commit a168fec
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions common/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package config

import (
"io/ioutil"
"os"
"testing"

"github.com/kirsle/configdir"
"gotest.tools/v3/assert"
)

func setup(t *testing.T, name string) {
newConfigDir, err := ioutil.TempDir(os.TempDir(), "config_"+name)
assert.NilError(t, err)
t.Setenv("XDG_CONFIG_HOME", newConfigDir)
t.Setenv("HOME", newConfigDir)

configdir.Refresh()
}

func Test_SimpleWriteRead(t *testing.T) {
setup(t, "SimpleWriteRead")

c := &Config{Repos: []string{"/home/xyz/hello"}}
err := Write(c)
assert.NilError(t, err)

c2, err := Read()
assert.NilError(t, err)

assert.DeepEqual(t, c, c2)
}

func Test_ReadEmpty(t *testing.T) {
setup(t, "ReadEmpty")

c, err := Read()
assert.NilError(t, err)
assert.Assert(t, len(c.Repos) == 0)
}
2 changes: 2 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
- Make sure that branch has a proper remote tracking branch

* Write about how to handle the case with an ssh-agent running

* When stopping the daemon, do not do anything if it is not running

0 comments on commit a168fec

Please sign in to comment.