示例#1
0
func TestReadFile(t *testing.T) {
	tmpdir := testutils.TempDir()
	defer os.RemoveAll(tmpdir)

	settings := NewSettings()
	settings.KeyFile = path.Join(tmpdir, "test2")

	key := "testkey4234"
	if err := ioutil.WriteFile(settings.KeyFile, []byte(key), 0700); err != nil {
		t.Fatal(err)
	}

	s := New()
	defer s.Stop()
	s.Init(settings)

	// Check that the key has been read properly.
	if s.key != key {
		t.Errorf("Expected key %q, got %q", s.key, key)
	}
}
示例#2
0
func TestCreateFile(t *testing.T) {
	tmpdir := testutils.TempDir()
	defer os.RemoveAll(tmpdir)

	settings := NewSettings()
	settings.KeyFile = path.Join(tmpdir, "test1")

	s := New()
	defer s.Stop()
	s.Init(settings)

	// Check that key file has been written and is what we expect.
	key, err := ioutil.ReadFile(settings.KeyFile)
	if err != nil {
		t.Fatal(err)
	}

	if s.key != string(key) {
		t.Errorf("Expected key %q, got %q", s.key, string(key))
	}
}