Esempio n. 1
0
func TestUploadToS3(t *testing.T) {
	cases := []struct {
		url           string
		widht, height uint
		expected      string
	}{
		{"marinhero.com", 1024, 768,
			"https://s3.amazonaws.com/" +
				"snapshotswootric/marinhero.com1024x768.png"},
		{"wootric.com", 1024, 768,
			"https://s3.amazonaws.com/" +
				"snapshotswootric/wootric.com1024x768.png"},
		{"", 0, 0, ""},
	}
	var shotinfo urlbox.ShotData
	for _, tCase := range cases {
		shotinfo.URL = tCase.url
		shotinfo.Width = tCase.widht
		shotinfo.Height = tCase.height
		urlbox.CreateShot(shotinfo)
		output := uploadToS3(shotinfo)
		if output != tCase.expected {
			t.Errorf("[!CreateShot]IN: %q EXPECTED: %q GOT: %q",
				shotinfo,
				tCase.expected,
				output)
		}
	}
}
Esempio n. 2
0
func indexHandler(w http.ResponseWriter, r *http.Request) {
	lp := path.Join("templates", "index.html")
	index := Page{Title: "SnapMaker - By Marin Alcaraz"}

	t, err := template.ParseFiles(lp)
	if err != nil {
		log.Fatal("[!]indexHandler:", err)
	}
	if r.Method == "POST" {
		r.ParseForm()
		data, strErr := validForm(r.Form)
		if strErr != "" {
			index.Messages = strErr
		} else {
			if urlbox.CreateShot(data) == "OK" {
				index.S3Link = uploadToS3(data)
			} else {
				index.Messages = "API returned KO - Please verify your input values"
			}
		}
	}
	t.Execute(w, index)
}