package recipe

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

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

func TestIsDirty(t *testing.T) {
	r := Get("abra-test-recipe")

	if err := r.EnsureExists(); err != nil {
		t.Fatal(err)
	}

	if err := r.IsDirty(); err != nil {
		t.Fatal(err)
	}

	assert.False(t, r.Dirty)

	fpath := filepath.Join(r.Dir, "foo.txt")
	f, err := os.Create(fpath)
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	defer t.Cleanup(func() {
		os.Remove(fpath)
	})

	if err := r.IsDirty(); err != nil {
		t.Fatal(err)
	}

	assert.True(t, r.Dirty)
}
