github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/repo/fsrepo/serialize/serialize_test.go (about)

     1  package fsrepo
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	config "github.com/ipfs/go-ipfs/repo/config"
     8  )
     9  
    10  func TestConfig(t *testing.T) {
    11  	const filename = ".ipfsconfig"
    12  	const dsPath = "/path/to/datastore"
    13  	cfgWritten := new(config.Config)
    14  	cfgWritten.Datastore.Path = dsPath
    15  	err := WriteConfigFile(filename, cfgWritten)
    16  	if err != nil {
    17  		t.Error(err)
    18  	}
    19  	cfgRead, err := Load(filename)
    20  	if err != nil {
    21  		t.Error(err)
    22  		return
    23  	}
    24  	if cfgWritten.Datastore.Path != cfgRead.Datastore.Path {
    25  		t.Fail()
    26  	}
    27  	st, err := os.Stat(filename)
    28  	if err != nil {
    29  		t.Fatalf("cannot stat config file: %v", err)
    30  	}
    31  	if g := st.Mode().Perm(); g&0117 != 0 {
    32  		t.Errorf("config file should not be executable or accessible to world: %v", g)
    33  	}
    34  }