aboutsummaryrefslogtreecommitdiffstats
path: root/repository/config_testing.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-09-27 19:25:37 +0200
committerMichael Muré <batolettre@gmail.com>2020-09-29 20:42:21 +0200
commit4f172432b1fb983c57aa258a93e24cbb36c8e1fb (patch)
treef3f057474afa38ca3dbdf1975d406214b00f3b1d /repository/config_testing.go
parent71b7eb14010be0c7799b4d5394798c89e379891b (diff)
downloadgit-bug-4f172432b1fb983c57aa258a93e24cbb36c8e1fb.tar.gz
repo: fix manu bugs in go-git config
Diffstat (limited to 'repository/config_testing.go')
-rw-r--r--repository/config_testing.go97
1 files changed, 75 insertions, 22 deletions
diff --git a/repository/config_testing.go b/repository/config_testing.go
index 25639d59..445f8721 100644
--- a/repository/config_testing.go
+++ b/repository/config_testing.go
@@ -2,62 +2,115 @@ package repository
import (
"testing"
+ "time"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func testConfig(t *testing.T, config Config) {
+ // string
err := config.StoreString("section.key", "value")
- assert.NoError(t, err)
+ require.NoError(t, err)
val, err := config.ReadString("section.key")
- assert.NoError(t, err)
- assert.Equal(t, "value", val)
+ require.NoError(t, err)
+ require.Equal(t, "value", val)
- err = config.StoreString("section.true", "true")
- assert.NoError(t, err)
+ // bool
+ err = config.StoreBool("section.true", true)
+ require.NoError(t, err)
val2, err := config.ReadBool("section.true")
- assert.NoError(t, err)
- assert.Equal(t, true, val2)
+ require.NoError(t, err)
+ require.Equal(t, true, val2)
+ // timestamp
+ err = config.StoreTimestamp("section.time", time.Unix(1234, 0))
+ require.NoError(t, err)
+
+ val3, err := config.ReadTimestamp("section.time")
+ require.NoError(t, err)
+ require.Equal(t, time.Unix(1234, 0), val3)
+
+ // ReadAll
configs, err := config.ReadAll("section")
- assert.NoError(t, err)
- assert.Equal(t, map[string]string{
+ require.NoError(t, err)
+ require.Equal(t, map[string]string{
"section.key": "value",
"section.true": "true",
+ "section.time": "1234",
}, configs)
+ // RemoveAll
err = config.RemoveAll("section.true")
- assert.NoError(t, err)
+ require.NoError(t, err)
configs, err = config.ReadAll("section")
- assert.NoError(t, err)
- assert.Equal(t, map[string]string{
- "section.key": "value",
+ require.NoError(t, err)
+ require.Equal(t, map[string]string{
+ "section.key": "value",
+ "section.time": "1234",
}, configs)
_, err = config.ReadBool("section.true")
- assert.Equal(t, ErrNoConfigEntry, err)
+ require.Equal(t, ErrNoConfigEntry, err)
err = config.RemoveAll("section.nonexistingkey")
- assert.Error(t, err)
+ require.Error(t, err)
err = config.RemoveAll("section.key")
- assert.NoError(t, err)
+ require.NoError(t, err)
_, err = config.ReadString("section.key")
- assert.Equal(t, ErrNoConfigEntry, err)
+ require.Equal(t, ErrNoConfigEntry, err)
err = config.RemoveAll("nonexistingsection")
- assert.Error(t, err)
+ require.Error(t, err)
+
+ err = config.RemoveAll("section.time")
+ require.NoError(t, err)
err = config.RemoveAll("section")
- assert.Error(t, err)
+ require.Error(t, err)
_, err = config.ReadString("section.key")
- assert.Error(t, err)
+ require.Error(t, err)
err = config.RemoveAll("section.key")
- assert.Error(t, err)
+ require.Error(t, err)
+
+ // section + subsections
+ require.NoError(t, config.StoreString("section.opt1", "foo"))
+ require.NoError(t, config.StoreString("section.opt2", "foo2"))
+ require.NoError(t, config.StoreString("section.subsection.opt1", "foo3"))
+ require.NoError(t, config.StoreString("section.subsection.opt2", "foo4"))
+ require.NoError(t, config.StoreString("section.subsection.subsection.opt1", "foo5"))
+ require.NoError(t, config.StoreString("section.subsection.subsection.opt2", "foo6"))
+
+ all, err := config.ReadAll("section")
+ require.NoError(t, err)
+ require.Equal(t, map[string]string{
+ "section.opt1": "foo",
+ "section.opt2": "foo2",
+ "section.subsection.opt1": "foo3",
+ "section.subsection.opt2": "foo4",
+ "section.subsection.subsection.opt1": "foo5",
+ "section.subsection.subsection.opt2": "foo6",
+ }, all)
+
+ all, err = config.ReadAll("section.subsection")
+ require.NoError(t, err)
+ require.Equal(t, map[string]string{
+ "section.subsection.opt1": "foo3",
+ "section.subsection.opt2": "foo4",
+ "section.subsection.subsection.opt1": "foo5",
+ "section.subsection.subsection.opt2": "foo6",
+ }, all)
+
+ all, err = config.ReadAll("section.subsection.subsection")
+ require.NoError(t, err)
+ require.Equal(t, map[string]string{
+ "section.subsection.subsection.opt1": "foo5",
+ "section.subsection.subsection.opt2": "foo6",
+ }, all)
}