//go:build windows

package util

import (
	"os"
	"path/filepath"
	"testing"

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

// TestWritable_NewFile verifies that a freshly created regular file is writable.
func TestWritable_NewFile(t *testing.T) {
	t.Parallel()

	dir := t.TempDir()
	path := filepath.Join(dir, "file.txt")

	err := os.WriteFile(path, []byte("x"), 0o600)
	require.NoError(t, err)

	ok, err := Writable(path)
	require.NoError(t, err)
	require.True(t, ok)
}

// TestWritable_NewDirectory verifies that a freshly created directory is writable
// by checking that a temp file can be created inside it.
func TestWritable_NewDirectory(t *testing.T) {
	t.Parallel()

	dir := t.TempDir()

	ok, err := Writable(dir)
	require.NoError(t, err)
	require.True(t, ok)
}

// TestWritable_MissingPath verifies that a missing path returns an error from Stat.
func TestWritable_MissingPath(t *testing.T) {
	t.Parallel()

	dir := t.TempDir()
	path := filepath.Join(dir, "missing")

	ok, err := Writable(path)
	require.Error(t, err)
	require.False(t, ok)
}
