//go:build unix || (js && wasm) || wasip1

package util_test

import (
	"galaxy/util"
	"os"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestWritable(t *testing.T) {
	root := t.ArtifactDir()

	ok, err := util.Writable(root)
	assert.NoError(t, err, "directory writable check")
	assert.True(t, ok, "directory should be writable")

	if os.Geteuid() == 0 {
		t.Skip("/usr/lib writability check is meaningful only for unprivileged users; root inside containers can write everywhere")
	}
	ok, err = util.Writable(nonWritableDir)
	assert.NoError(t, err, "system directory writable check")
	assert.False(t, ok, "system directory should not be writable")
}
