Exemplo n.º 1
0
func TestAuthEncodeDecodeUser(t *testing.T) {
	auth, _ := buildAuth()
	token := auth.GenerateToken()
	user := model.NewUser(token)
	encoded, err := auth.encodeUser(user)
	test.AssertNotErr("Auth.encodeUser", err, t)

	_, err2 := auth.decodeUser(encoded)
	test.AssertNotErr("Auth.edecodeUser", err2, t)
}
Exemplo n.º 2
0
func TestS3FileStorageSaveDelete(t *testing.T) {
	cfg := getConfig()
	storage := NewS3FileStorage(cfg.Get("s3_region"), cfg.Get("s3_images_bucket_test"))
	filename := "test.jpg"
	file, err := os.Open("../test_fixtures/test.jpg")
	test.AssertNotErr("osOpen", err, t)
	_, errSave := storage.Save(file, filename)
	test.AssertNotErr("S3FileStorage.Save", errSave, t)
	errDelete := storage.Delete(filename)
	test.AssertNotErr("S3FileStorage.Delete", errDelete, t)
}
Exemplo n.º 3
0
func TestAuthGetSession(t *testing.T) {
	auth, _ := buildAuth()
	token := auth.GenerateToken()
	user := model.NewUser(token)
	err := auth.CreateSession(user)
	test.AssertNotErr("Auth.CreateSession", err, t)
	user, errGet := auth.GetSession(token)

	test.AssertNotErr("Auth.GetSession", errGet, t)
	test.AssertNotNil("Auth.GetSession", user, t)
}
Exemplo n.º 4
0
func TestAuthUpdateSession(t *testing.T) {
	auth, _ := buildAuth()
	token := auth.GenerateToken()
	user := model.NewUser(token)
	err := auth.CreateSession(user)
	test.AssertNotErr("Auth.CreateSession", err, t)

	user.ID = "updated"
	errUpd := auth.UpdateSession(user)
	usercheck, errGet := auth.GetSession(token)

	test.AssertNotErr("Auth.UpdateSession", errUpd, t)
	test.AssertNotErr("formatURL", errGet, t)
	test.Assert("Auth.UpdateSession", user.ID, usercheck.ID, t)
}
Exemplo n.º 5
0
func TestFlickrProviderSearch(t *testing.T) {
	cfg := getConfig()
	p := NewFlickrProvider(cfg.Get("flickr_key"), cfg.Get("flickr_secret_key"))
	result, err := p.Search("nature", 1)

	test.AssertNotErr("FlickrProvider.Search()", err, t)
	test.AssertNot("FlickrProvider.Search() SearchResult.Pages", 0, result.Pages, t)
}
Exemplo n.º 6
0
func TestAuthGetSessionUnknownToken(t *testing.T) {
	auth, _ := buildAuth()
	token := auth.GenerateToken()
	user, err := auth.GetSession(token)

	test.AssertNotErr("Auth.GetSession", err, t)
	test.AssertNil("Auth.GetSession", user, t)
}
Exemplo n.º 7
0
func TestDiscoverDownloadFile(t *testing.T) {
	cfg := getConfig()
	dest := path.Join(getRootDir(), cfg.Get("tmp_dir"), "downloadTest.jpg")
	p := NewFlickrProvider(cfg.Get("flickr_key"), cfg.Get("flickr_secret_key"))
	img := NewDiscover(p)
	filename, err := img.DownloadFile("https://farm6.staticflickr.com/5337/17095007133_61efedd70b_z.jpg", dest)

	test.AssertNotErr("Discover.DownloadFile", err, t)
	test.AssertNot("Discover.DownloadFile", "", filename, t)
}
Exemplo n.º 8
0
func TestFormatURL(t *testing.T) {
	params := map[string]string{
		"param1": "val1",
		"param2": "val2",
	}
	result, err := formatURL("http://example.com/path", params)
	expected := "http://example.com/path?param1=val1&param2=val2"

	test.AssertNotErr("formatURL", err, t)
	test.Assert("formatURL", expected, result, t)
}
Exemplo n.º 9
0
func TestRESTResponseWrite(t *testing.T) {
	response := NewRESTResponse()
	res := httptest.NewRecorder()
	response.Generate(res)
	test.Assert("RESTResponse.Write Header Content-Type", "application/json", res.Header().Get("Content-Type"), t)
	test.Assert("RESTResponse.Write status code", http.StatusOK, res.Code, t)

	var js map[string]interface{}
	err := json.Unmarshal(res.Body.Bytes(), &js)
	test.AssertNotErr("RESTResponse.Write", err, t)
}
Exemplo n.º 10
0
func TestAuthRandString(t *testing.T) {
	auth, _ := buildAuth()
	rand := auth.randString(10)
	if len(rand) != 10 {
		t.Errorf("Auth.randString() returned a string of length %s, expected 10", len(rand))
	}
	pattern := "[a-z0-9]+"
	match, err := regexp.MatchString(pattern, rand)

	test.AssertNotErr("Auth.randString", err, t)
	test.Assert("Auth.randString", true, match, t)
}
Exemplo n.º 11
0
func TestNewContext(t *testing.T) {
	ctx, _, _ := buildContext()
	_, err := os.Stat(ctx.RootDir)
	test.AssertNotErr("os.Stat(ctx.RootDir)", err, t)
	test.Assert("Context.RootDir", false, os.IsNotExist(err), t)
}