You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

80 lines
2.0 KiB

  1. package dynamodb_test
  2. import (
  3. "github.com/goamz/goamz/dynamodb"
  4. . "gopkg.in/check.v1"
  5. )
  6. type TableSuite struct {
  7. TableDescriptionT dynamodb.TableDescriptionT
  8. DynamoDBTest
  9. }
  10. func (s *TableSuite) SetUpSuite(c *C) {
  11. setUpAuth(c)
  12. s.DynamoDBTest.TableDescriptionT = s.TableDescriptionT
  13. s.server = &dynamodb.Server{dynamodb_auth, dynamodb_region}
  14. pk, err := s.TableDescriptionT.BuildPrimaryKey()
  15. if err != nil {
  16. c.Skip(err.Error())
  17. }
  18. s.table = s.server.NewTable(s.TableDescriptionT.TableName, pk)
  19. // Cleanup
  20. s.TearDownSuite(c)
  21. }
  22. var table_suite = &TableSuite{
  23. TableDescriptionT: dynamodb.TableDescriptionT{
  24. TableName: "DynamoDBTestMyTable",
  25. AttributeDefinitions: []dynamodb.AttributeDefinitionT{
  26. dynamodb.AttributeDefinitionT{"TestHashKey", "S"},
  27. dynamodb.AttributeDefinitionT{"TestRangeKey", "N"},
  28. dynamodb.AttributeDefinitionT{"TestSecKey", "N"},
  29. },
  30. KeySchema: []dynamodb.KeySchemaT{
  31. dynamodb.KeySchemaT{"TestHashKey", "HASH"},
  32. dynamodb.KeySchemaT{"TestRangeKey", "RANGE"},
  33. },
  34. GlobalSecondaryIndexes: []dynamodb.GlobalSecondaryIndexT{
  35. dynamodb.GlobalSecondaryIndexT{
  36. IndexName: "gsiTest",
  37. KeySchema: []dynamodb.KeySchemaT{
  38. dynamodb.KeySchemaT{"TestHashKey", "HASH"},
  39. dynamodb.KeySchemaT{"TestSecKey", "RANGE"},
  40. },
  41. Projection: dynamodb.ProjectionT{"ALL"},
  42. ProvisionedThroughput: dynamodb.ProvisionedThroughputT{
  43. ReadCapacityUnits: 1,
  44. WriteCapacityUnits: 1,
  45. },
  46. },
  47. },
  48. ProvisionedThroughput: dynamodb.ProvisionedThroughputT{
  49. ReadCapacityUnits: 1,
  50. WriteCapacityUnits: 1,
  51. },
  52. },
  53. }
  54. var _ = Suite(table_suite)
  55. func (s *TableSuite) TestCreateListTable(c *C) {
  56. status, err := s.server.CreateTable(s.TableDescriptionT)
  57. if err != nil {
  58. c.Fatal(err)
  59. }
  60. if status != "ACTIVE" && status != "CREATING" {
  61. c.Error("Expect status to be ACTIVE or CREATING")
  62. }
  63. s.WaitUntilStatus(c, "ACTIVE")
  64. tables, err := s.server.ListTables()
  65. if err != nil {
  66. c.Fatal(err)
  67. }
  68. c.Check(len(tables), Not(Equals), 0)
  69. c.Check(findTableByName(tables, s.TableDescriptionT.TableName), Equals, true)
  70. }