Ejemplo n.º 1
0
func TestRedisInsert(t *testing.T) {
	env := Setup()
	rc := env.CL
	// Let's start by generating a hash
	const time_form = "2015-07-13 17:28:27.043022906"
	test_time, _ := time.Parse(time_form, "2015-07-13 17:28:27.043022906")
	test_struct := generator.LinkGen{
		"http://google.com",
		"*****@*****.**",
		test_time,
	}

	gen_hash := generator.GenerateLink(test_struct)

	err := controllers.RedisInsertLink(test_struct, gen_hash, env)
	if err != nil {
		t.Error(err)
	}

	// Test out both the link we expect the hash to redirect to, and the username it is attached to
	rl, _ := rc.HGet(gen_hash, "link").Result()

	if rl != "http://google.com" {
		t.Errorf("Expected http://google.com, got %s", rl)
	}

	ru, _ := rc.HGet(gen_hash, "username").Result()

	if ru != "*****@*****.**" {
		t.Errorf("Expected [email protected], got %s", ru)
	}

	// Let's clean up Redis instance
	rc.Del(gen_hash)
}
Ejemplo n.º 2
0
func genHash() string {
	const time_form = "2015-07-13 17:28:27.043022906"
	test_time, _ := time.Parse(time_form, "2015-07-13 17:28:27.043022906")
	test_struct := generator.LinkGen{
		"http://google.com",
		"*****@*****.**",
		test_time,
	}

	gen_hash := generator.GenerateLink(test_struct)

	return gen_hash
}