mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +08:00
Merge pull request #54 from jbenet/fix/config-test
fix(config) failing test
This commit is contained in:
@ -43,7 +43,7 @@ func initCmd(c *commander.Command, inp []string) error {
|
|||||||
}
|
}
|
||||||
cfg := new(config.Config)
|
cfg := new(config.Config)
|
||||||
|
|
||||||
cfg.Datastore = new(config.Datastore)
|
cfg.Datastore = config.Datastore{}
|
||||||
dspath, err := u.TildeExpansion("~/.go-ipfs/datastore")
|
dspath, err := u.TildeExpansion("~/.go-ipfs/datastore")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -30,7 +30,7 @@ type SavedPeer struct {
|
|||||||
// Config is used to load IPFS config files.
|
// Config is used to load IPFS config files.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Identity *Identity
|
Identity *Identity
|
||||||
Datastore *Datastore
|
Datastore Datastore
|
||||||
Peers []*SavedPeer
|
Peers []*SavedPeer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfig(t *testing.T) {
|
func TestConfig(t *testing.T) {
|
||||||
|
const filename = ".ipfsconfig"
|
||||||
cfg, err := Load(".ipfsconfig")
|
const dsPath = "/path/to/datastore"
|
||||||
|
cfgWritten := new(Config)
|
||||||
|
cfgWritten.Datastore.Path = dsPath
|
||||||
|
err := WriteConfigFile(filename, cfgWritten)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
cfgRead, err := Load(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if cfgWritten.Datastore.Path != cfgRead.Datastore.Path {
|
||||||
fmt.Printf(cfg.Datastore.Path)
|
t.Fail()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@ func TestInitialization(t *testing.T) {
|
|||||||
good := []*config.Config{
|
good := []*config.Config{
|
||||||
&config.Config{
|
&config.Config{
|
||||||
Identity: id,
|
Identity: id,
|
||||||
Datastore: &config.Datastore{
|
Datastore: config.Datastore{
|
||||||
Type: "memory",
|
Type: "memory",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
&config.Config{
|
&config.Config{
|
||||||
Identity: id,
|
Identity: id,
|
||||||
Datastore: &config.Datastore {
|
Datastore: config.Datastore{
|
||||||
Type: "leveldb",
|
Type: "leveldb",
|
||||||
Path: ".testdb",
|
Path: ".testdb",
|
||||||
},
|
},
|
||||||
@ -31,10 +31,10 @@ func TestInitialization(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bad := []*config.Config{
|
bad := []*config.Config{
|
||||||
&config.Config{Identity: id, Datastore: &config.Datastore{}},
|
&config.Config{Identity: id, Datastore: config.Datastore{}},
|
||||||
&config.Config{Identity: id, Datastore: &config.Datastore{Type: "badtype"}},
|
&config.Config{Identity: id, Datastore: config.Datastore{Type: "badtype"}},
|
||||||
&config.Config{},
|
&config.Config{},
|
||||||
&config.Config{Datastore: &config.Datastore{Type: "memory"}},
|
&config.Config{Datastore: config.Datastore{Type: "memory"}},
|
||||||
nil,
|
nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,14 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
|
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
|
||||||
lds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
|
lds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
|
||||||
config "github.com/jbenet/go-ipfs/config"
|
config "github.com/jbenet/go-ipfs/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeDatastore(cfg *config.Datastore) (ds.Datastore, error) {
|
func makeDatastore(cfg config.Datastore) (ds.Datastore, error) {
|
||||||
if cfg == nil || len(cfg.Type) == 0 {
|
if len(cfg.Type) == 0 {
|
||||||
return nil, fmt.Errorf("config datastore.type required")
|
return nil, fmt.Errorf("config datastore.type required")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ func makeDatastore(cfg *config.Datastore) (ds.Datastore, error) {
|
|||||||
return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
|
return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeLevelDBDatastore(cfg *config.Datastore) (ds.Datastore, error) {
|
func makeLevelDBDatastore(cfg config.Datastore) (ds.Datastore, error) {
|
||||||
if len(cfg.Path) == 0 {
|
if len(cfg.Path) == 0 {
|
||||||
return nil, fmt.Errorf("config datastore.path required for leveldb")
|
return nil, fmt.Errorf("config datastore.path required for leveldb")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user