Exemplo n.º 1
0
// createConfigurationFile creates a temporary configuration file.
func createConfigurationFile(assert audit.Assertion, content string) (*audit.TempDir, string) {
	tempDir := audit.NewTempDir(assert)
	configFile, err := ioutil.TempFile(tempDir.String(), "configuration")
	assert.Nil(err)
	configFileName := configFile.Name()
	_, err = configFile.WriteString(content)
	assert.Nil(err)
	configFile.Close()

	return tempDir, configFileName
}
Exemplo n.º 2
0
// TestTempDirRestore tests the restoring of temporary created
// directories.
func TestTempDirRestore(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)

	td := audit.NewTempDir(assert)
	assert.NotNil(td)
	tds := td.String()
	fi, err := os.Stat(tds)
	assert.Nil(err)
	assert.True(fi.IsDir())

	td.Restore()
	fi, err = os.Stat(tds)
	assert.ErrorMatch(err, "stat .* no such file or directory")
}
Exemplo n.º 3
0
// TestReadFile tests reading a configuration out of a file.
func TestReadFile(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	tempDir := audit.NewTempDir(assert)
	defer tempDir.Restore()
	configFile, err := ioutil.TempFile(tempDir.String(), "configuration")
	assert.Nil(err)
	configFileName := configFile.Name()
	_, err = configFile.WriteString("{config {foo 42}{bar 24}}")
	assert.Nil(err)
	configFile.Close()

	config, err := configuration.ReadFile(configFileName)
	assert.Nil(err)
	v, err := config.At("foo").Value()
	assert.Nil(err)
	assert.Equal(v, "42")
	v, err = config.At("bar").Value()
	assert.Nil(err)
	assert.Equal(v, "24")

	_, err = configuration.ReadFile("some-not-existing-configuration-file-due-to-wierd-name")
	assert.ErrorMatch(err, `.* cannot read configuration file .*`)
}
Exemplo n.º 4
0
// TestTempDirCreate tests the creation of temporary directories.
func TestTempDirCreate(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	testDir := func(dir string) {
		fi, err := os.Stat(dir)
		assert.Nil(err)
		assert.True(fi.IsDir())
		assert.Equal(fi.Mode().Perm(), os.FileMode(0700))
	}

	td := audit.NewTempDir(assert)
	assert.NotNil(td)
	defer td.Restore()

	tds := td.String()
	assert.NotEmpty(tds)
	testDir(tds)

	sda := td.Mkdir("subdir", "foo")
	assert.NotEmpty(sda)
	testDir(sda)
	sdb := td.Mkdir("subdir", "bar")
	assert.NotEmpty(sdb)
	testDir(sdb)
}