package winpe

import (
	"bytes"
	"encoding/base64"
	"io"
	"os"
	"testing"

	"github.com/smallstep/assert"
)

// This test will write the chrome.exe installer into a temporary file
// Then it will just run the extractPE function.
func TestExtract(t *testing.T) {
	tmpfile, err := os.CreateTemp("", "step-crypto-winpe-extract-chrome.*.exe")
	assert.NoError(t, err)
	defer os.Remove(tmpfile.Name())
	defer tmpfile.Close()

	dec := base64.NewDecoder(base64.StdEncoding, bytes.NewReader(ChromeExe))

	_, err = io.Copy(tmpfile, dec)
	assert.NoError(t, err)

	assert.NoError(t, extractPE(tmpfile.Name()))
}

// Downloaded from the chrome website and base64 encoded from cli
var ChromeExe = []byte(`
[encoded data, 1761760 characters]
`)
