core_test.go 760 Bytes
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2 3
package core

import (
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
4
	"testing"
Jeromy's avatar
Jeromy committed
5 6

	config "github.com/jbenet/go-ipfs/config"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
7 8 9 10
)

func TestDatastores(t *testing.T) {

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
11 12 13 14
	good := []*config.Config{
		&config.Config{Datastore: &config.Datastore{Type: "memory"}},
		&config.Config{Datastore: &config.Datastore{Type: "leveldb", Path: ".testdb"}},
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
15

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
16 17 18 19 20 21
	bad := []*config.Config{
		&config.Config{Datastore: &config.Datastore{}},
		&config.Config{Datastore: &config.Datastore{Type: "badtype"}},
		&config.Config{},
		nil,
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
22

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
23
	for i, c := range good {
Jeromy's avatar
Jeromy committed
24
		n, err := NewIpfsNode(c, false)
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
25 26 27 28
		if n == nil || err != nil {
			t.Error("Should have constructed.", i, err)
		}
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
29

Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
30
	for i, c := range bad {
Jeromy's avatar
Jeromy committed
31
		n, err := NewIpfsNode(c, false)
Juan Batiz-Benet's avatar
go fmt  
Juan Batiz-Benet committed
32 33 34 35
		if n != nil || err == nil {
			t.Error("Should have failed to construct.", i)
		}
	}
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
36
}