Skip to content

Instantly share code, notes, and snippets.

@kevina
Created June 16, 2017 21:56
Show Gist options
  • Save kevina/50c1255543cbc8a674a30c7f6e674abf to your computer and use it in GitHub Desktop.
Save kevina/50c1255543cbc8a674a30c7f6e674abf to your computer and use it in GitHub Desktop.
Start of test case.
package fsrepo
import (
"encoding/json"
"testing"
"os"
"io/ioutil"
"reflect"
//"fmt"
syncmount "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/syncmount"
//levelds "gx/ipfs/QmaHHmfEozrrotyhyN44omJouyuEtx6ahddqV6W5yRaUSQ/go-ds-leveldb"
config "github.com/ipfs/go-ipfs/repo/config"
)
var defaultConfig = []byte(`{
"StorageMax": "10GB",
"StorageGCWatermark": 90,
"GCPeriod": "1h",
"Spec": {
"mounts": [
{
"child": {
"path": "blocks",
"shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
"sync": true,
"type": "flatfs"
},
"mountpoint": "/blocks",
"prefix": "flatfs.datastore",
"type": "measure"
},
{
"child": {
"compression": "none",
"path": "datastore",
"type": "levelds"
},
"mountpoint": "/",
"prefix": "leveldb.datastore",
"type": "measure"
}
],
"type": "mount"
},
"HashOnRead": false,
"BloomFilterSize": 0
}`)
func TestDefaultDatastoreConfig(t *testing.T) {
config := new(config.Datastore)
err := json.Unmarshal(defaultConfig, config)
if err != nil {
t.Fatal(err)
}
dir, err := ioutil.TempDir("", "ipfs-datastore-config-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
repo := FSRepo{path: dir}
ds, err := repo.constructDatastore(config.Spec)
if err != nil {
t.Fatal(err)
}
mount, ok := ds.(*syncmount.Datastore)
if !ok {
t.Fatal("expected mount datastore at top level")
}
v := reflect.ValueOf(*mount)
mounts := make([]string, 2)
mounts[0] = v.FieldByName("mounts").Index(0).FieldByName("Prefix").FieldByName("string").String()
mounts[1] = v.FieldByName("mounts").Index(1).FieldByName("Prefix").FieldByName("string").String()
// check for two mounts, one at "/blocks" that should be a measure datastore
// and one at "/" that should be leveldb datastore
println(mounts[0])
println(mounts[1])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment