1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-10-04 12:31:00 +00:00
go-mtree/xattr/xattr_test.go
Aleksa Sarai 3252a4ad82
test: migrate most tests to testify
testify makes most bog-standard test checks much easier to read and
maintain, and is quite widely used. It wasn't really well known back
when go-mtree was first written, but the migration is fairly
straight-forward for most tests.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2025-09-20 12:43:45 +10:00

38 lines
874 B
Go

//go:build linux
// +build linux
package xattr
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestXattr(t *testing.T) {
testDir, present := os.LookupEnv("MTREE_TESTDIR")
if present == false {
testDir = "."
}
fh, err := os.CreateTemp(testDir, "xattr.")
require.NoError(t, err)
path := fh.Name()
defer os.Remove(path)
require.NoError(t, fh.Close())
expected := []byte("1234")
err = Set(path, "user.testing", expected)
require.NoErrorf(t, err, "set user.testing xattr %s", path)
l, err := List(path)
require.NoErrorf(t, err, "list xattr %s", path)
assert.NotEmptyf(t, l, "expected at least one xattr in list for %s", path)
got, err := Get(path, "user.testing")
require.NoErrorf(t, err, "get user.testing xattr %s", path)
assert.Equalf(t, expected, got, "user.testing xattr %s", path)
}