Ejemplo n.º 1
0
func TestTableActions(t *testing.T) {
	tables := []string{"abc", "def", "ghi"}
	assert, client := funcTest.setUp(t)
	for _, name := range tables {
		_, err := client.CreateTable(schema.NewCreateRequest(name).HashKey("Id", schema.Number))
		if e, ok := err.(*dynago.Error); !ok || e.Type != dynago.ErrorResourceInUse {
			assert.NoError(err)
		}
	}
	list, err := client.ListTables().Limit(10).Execute()
	assert.NoError(err)
	assert.NotNil(list)
	assert.True(len(list.TableNames) > len(tables))
	assert.Nil(list.Next())

	// Pagination of tables should work
	list1, err := client.ListTables().Limit(2).Execute()
	assert.NoError(err)
	assert.NotNil(list1.Next())
	assert.Equal(2, len(list1.TableNames))
	assert.Equal(list.TableNames[:2], list1.TableNames[:2])
	list2, err := list1.Next().Execute()
	assert.Equal(list.TableNames[2:4], list2.TableNames[:2])

	for _, name := range tables {
		_, err := client.DeleteTable(name)
		assert.NoError(err)
	}

}
Ejemplo n.º 2
0
func makeTables(t *testing.T, client *dynago.Client) {
	complexIndexed := complexIndexedSchema()
	hashTable := schema.NewCreateRequest("Person").HashKey("Id", schema.Number)
	hashRange := schema.NewCreateRequest("Posts").
		HashKey("UserId", schema.Number).
		RangeKey("Dated", schema.Number)

	tables := []*schema.CreateRequest{hashTable, hashRange, complexIndexed}
	for _, table := range tables {
		_, err := client.CreateTable(table)
		if err != nil {
			if e, ok := err.(*dynago.Error); ok && e.Type == dynago.ErrorResourceInUse {
				continue
			}
			panic(err)
		}
	}
}
Ejemplo n.º 3
0
func ExampleClient_CreateTable_basic(client *dynago.Client) {
	// NewCreateRequest creates a table with simple defaults.
	// You can use chaining to set the hash and range keys.
	table1 := schema.NewCreateRequest("TableName").
		HashKey("UserId", schema.Number).
		RangeKey("Date", schema.String)

	table1.ProvisionedThroughput.ReadCapacityUnits = 45
	client.CreateTable(table1)
}