Example #1
0
func TestGetItemRange(t *testing.T) {
	if !*amazon {
		return
	}

	if !*amazon {
		t.Log("Amazon tests not enabled")
		return
	}

	auth, err := aws.EnvAuth()

	if err != nil {
		t.Log(err)
		t.FailNow()
	}

	server := dynamodb.Server{auth, aws.USEast}
	primary := dynamodb.NewStringAttribute("uuid_type", "")
	rangeK := dynamodb.NewNumericAttribute("time", "")
	key := dynamodb.PrimaryKey{primary, rangeK}
	table := server.NewTable("production_storyarc-accelerator-analytics",
		key)

	item, err := table.GetItem("aee5df14-6961-4baa-bad1-a1150576594f_MISSES", "1348187524")

	if err != nil {
		t.Log(err)
		t.FailNow()
	}

	fmt.Printf("Item : %s\n", item)

}
Example #2
0
func TestGetItem(t *testing.T) {
	if !*amazon {
		t.Log("Amazon tests not enabled")
		return
	}

	auth, err := aws.EnvAuth()

	if err != nil {
		t.Log(err)
		t.FailNow()
	}

	server := dynamodb.Server{auth, aws.USEast}
	primary := dynamodb.NewStringAttribute("domain", "")
	key := dynamodb.PrimaryKey{primary, nil}
	table := server.NewTable("production_storyarc-accelerator-sites",
		key)

	item, err := table.GetItem("ac-news.speedup.storytellerhq.com", "")

	if err != nil {
		t.Log(err)
		t.FailNow()
	}

	fmt.Printf("Item : %s\n", item)

}
Example #3
0
func TestUpdateQuery(t *testing.T) {
	auth := &aws.Auth{"", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
	server := dynamodb.Server{*auth, aws.USEast}
	primary := dynamodb.NewStringAttribute("domain", "")
	rangek := dynamodb.NewNumericAttribute("time", "")
	key := dynamodb.PrimaryKey{primary, rangek}
	table := server.NewTable("sites", key)

	countAttribute := dynamodb.NewNumericAttribute("count", "4")
	attributes := []dynamodb.Attribute{*countAttribute}

	q := dynamodb.NewQuery(table)
	q.AddKey(table, "test", "1234")
	q.AddUpdates(attributes, "ADD")

	queryString := []byte(q.String())

	json, err := simplejson.NewJson(queryString)

	if err != nil {
		t.Logf("JSON err : %s\n", err)
		t.Fatalf("Invalid JSON : %s\n", queryString)
	}

	tableName := json.Get("TableName").MustString()

	if tableName != "sites" {
		t.Fatalf("Expected tableName to be sites was : %s", tableName)
	}

	keyMap, err := json.Get("Key").Map()

	if err != nil {
		t.Fatalf("Expected a Key")
	}

	hashRangeKey := keyMap["HashKeyElement"]

	if hashRangeKey == nil {
		t.Fatalf("Expected a HashKeyElement found : %s", keyMap)
	}

	rangeKey := keyMap["RangeKeyElement"]

	if rangeKey == nil {
		t.Fatalf("Expected a RangeKeyElement found : %s", keyMap)
	}

}
Example #4
0
func TestGetItemQuery(t *testing.T) {
	auth := &aws.Auth{"", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
	server := dynamodb.Server{*auth, aws.USEast}
	primary := dynamodb.NewStringAttribute("domain", "")
	key := dynamodb.PrimaryKey{primary, nil}
	table := server.NewTable("sites", key)

	q := dynamodb.NewQuery(table)
	q.AddKey(table, "test", "")

	queryString := []byte(q.String())

	json, err := simplejson.NewJson(queryString)

	if err != nil {
		t.Logf("JSON err : %s\n", err)
		t.Fatalf("Invalid JSON : %s\n", queryString)
	}

	tableName := json.Get("TableName").MustString()

	if tableName != "sites" {
		t.Fatalf("Expected tableName to be sites was : %s", tableName)
	}

	keyMap, err := json.Get("Key").Map()

	if err != nil {
		t.Fatalf("Expected a Key")
	}

	hashRangeKey := keyMap["HashKeyElement"]

	if hashRangeKey == nil {
		t.Fatalf("Expected a HashKeyElement found : %s", keyMap)
	}

	if v, ok := hashRangeKey.(map[string]interface{}); ok {
		if val, ok := v["S"].(string); ok {
			if val != "test" {
				t.Fatalf("Expected HashKeyElement to have the value 'test' found : %s", val)
			}
		}
	} else {
		t.Fatalf("HashRangeKeyt had the wrong type found : %s", hashRangeKey)
	}
}