package pkg_test

import (
	"io/fs"
	"testing"

	"hakurei.app/check"
	"hakurei.app/internal/pkg"
)

func TestFile(t *testing.T) {
	t.Parallel()

	want := expectsFile{0}
	checkWithCache(t, []cacheTestCase{
		{"file", pkg.CValidateKnown, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
			cureMany(t, c, []cureStep{
				{"short", pkg.NewFile("null", []byte{0}), base.Append(
					"identifier",
					"3376ALA7hIUm2LbzH2fDvRezgzod1eTK_G6XjyOgbM2u-6swvkFaF0BOwSl_juBi",
				), want, pkg.WNew, nil},
			})
		}, expectsFS{
			".": {Mode: fs.ModeDir | 0700},

			"checksum":                            {Mode: fs.ModeDir | 0700},
			"checksum/" + pkg.Encode(want.hash()): {Mode: 0400, Data: []byte{0}},

			"identifier": {Mode: fs.ModeDir | 0700},
			"identifier/3376ALA7hIUm2LbzH2fDvRezgzod1eTK_G6XjyOgbM2u-6swvkFaF0BOwSl_juBi": {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/vsAhtPNo4waRNOASwrQwcIPTqb3SBuJOXw2G4T1mNmVZM-wrQTRllmgXqcIIoRcX")},

			"substitute": {Mode: fs.ModeDir | 0700},

			"work": {Mode: fs.ModeDir | 0700},
		}},
	})
}
