package pagewriter
import (
	"bytes"
	"html/template"
	"io/ioutil"
	"os"
	"path/filepath"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)
var _ = Describe("Templates", func() {
	var customDir string
	BeforeEach(func() {
		var err error
		customDir, err = ioutil.TempDir("", "oauth2-proxy-templates-test")
		Expect(err).ToNot(HaveOccurred())
		templateHTML := `{{.TestString}} {{.TestString | ToLower}} {{.TestString | ToUpper}}`
		signInFile := filepath.Join(customDir, signInTemplateName)
		Expect(ioutil.WriteFile(signInFile, []byte(templateHTML), 0600)).To(Succeed())
		errorFile := filepath.Join(customDir, errorTemplateName)
		Expect(ioutil.WriteFile(errorFile, []byte(templateHTML), 0600)).To(Succeed())
	})
	AfterEach(func() {
		Expect(os.RemoveAll(customDir)).To(Succeed())
	})
	Context("loadTemplates", func() {
		var data interface{}
		var t *template.Template
		BeforeEach(func() {
			data = struct {
				// For default templates
				ProxyPrefix string
				Redirect    string
				Footer      string
				// For default sign_in template
				SignInMessage string
				ProviderName  string
				CustomLogin   bool
				LogoData      string
				// For default error template
				StatusCode int
				Title      string
				Message    string
				// For custom templates
				TestString string
			}{
				ProxyPrefix: "",
				Redirect:    "",
				Footer:      "