package writer

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

func TestWriteImageCopiesFile(t *testing.T) {
	dir := t.TempDir()
	src := filepath.Join(dir, "src.img")
	dest := filepath.Join(dir, "dest.img")
	content := []byte("metis-test")
	if err := os.WriteFile(src, content, 0o644); err != nil {
		t.Fatalf("write src: %v", err)
	}
	if err := WriteImage(context.Background(), src, dest); err != nil {
		t.Fatalf("write image: %v", err)
	}
	got, err := os.ReadFile(dest)
	if err != nil {
		t.Fatalf("read dest: %v", err)
	}
	if string(got) != string(content) {
		t.Fatalf("expected %q got %q", string(content), string(got))
	}
}
