Skip to content

Commit

Permalink
Adding Table suffix to Create, Delete, and List methods on service cl…
Browse files Browse the repository at this point in the history
…ient (#15181)
  • Loading branch information
seankane-msft authored Jul 28, 2021
1 parent 6e69790 commit e165488
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions sdk/tables/aztable/table_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func NewTableClient(tableName string, serviceURL string, cred azcore.Credential,

// Create creates the table with the tableName specified when NewTableClient was called.
func (t *TableClient) Create(ctx context.Context) (TableResponseResponse, error) {
return t.service.Create(ctx, t.Name)
return t.service.CreateTable(ctx, t.Name)
}

// Delete deletes the table with the tableName specified when NewTableClient was called.
func (t *TableClient) Delete(ctx context.Context) (TableDeleteResponse, error) {
return t.service.Delete(ctx, t.Name)
return t.service.DeleteTable(ctx, t.Name)
}

// List queries the entities using the specified ListOptions.
Expand Down
6 changes: 3 additions & 3 deletions sdk/tables/aztable/table_service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (t *TableServiceClient) NewTableClient(tableName string) *TableClient {
}

// Create creates a table with the specified name.
func (t *TableServiceClient) Create(ctx context.Context, name string) (TableResponseResponse, error) {
func (t *TableServiceClient) CreateTable(ctx context.Context, name string) (TableResponseResponse, error) {
resp, err := t.client.Create(ctx, TableProperties{&name}, new(TableCreateOptions), new(QueryOptions))
if err == nil {
tableResp := resp.(TableResponseResponse)
Expand All @@ -50,7 +50,7 @@ func (t *TableServiceClient) Create(ctx context.Context, name string) (TableResp
}

// Delete deletes a table by name.
func (t *TableServiceClient) Delete(ctx context.Context, name string) (TableDeleteResponse, error) {
func (t *TableServiceClient) DeleteTable(ctx context.Context, name string) (TableDeleteResponse, error) {
return t.client.Delete(ctx, name, nil)
}

Expand All @@ -72,7 +72,7 @@ func (t *TableServiceClient) Delete(ctx context.Context, name string) (TableDele
// fmt.Printf("The page contains %i results.\n", len(resp.TableQueryResponse.Value))
// }
// err := pager.Err()
func (t *TableServiceClient) List(listOptions *ListOptions) TableQueryResponsePager {
func (t *TableServiceClient) ListTables(listOptions *ListOptions) TableQueryResponsePager {
return &tableQueryResponsePager{
client: t.client,
queryOptions: listOptions,
Expand Down
24 changes: 12 additions & 12 deletions sdk/tables/aztable/table_service_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func (s *tableServiceClientLiveTests) TestServiceErrors() {
tableName, err := getTableName(context)
require.NoError(err)

_, err = context.client.Create(ctx, tableName)
_, err = context.client.CreateTable(ctx, tableName)
delete := func() {
_, err := context.client.Delete(ctx, tableName)
_, err := context.client.DeleteTable(ctx, tableName)
if err != nil {
fmt.Printf("Error cleaning up test. %v\n", err.Error())
}
Expand All @@ -51,7 +51,7 @@ func (s *tableServiceClientLiveTests) TestServiceErrors() {
require.NoError(err)

// Create a duplicate table to produce an error
_, err = context.client.Create(ctx, tableName)
_, err = context.client.CreateTable(ctx, tableName)
var svcErr *runtime.ResponseError
errors.As(err, &svcErr)
require.Equal(svcErr.RawResponse().StatusCode, http.StatusConflict)
Expand All @@ -63,9 +63,9 @@ func (s *tableServiceClientLiveTests) TestCreateTable() {
tableName, err := getTableName(context)
require.NoError(err)

resp, err := context.client.Create(ctx, tableName)
resp, err := context.client.CreateTable(ctx, tableName)
delete := func() {
_, err := context.client.Delete(ctx, tableName)
_, err := context.client.DeleteTable(ctx, tableName)
if err != nil {
fmt.Printf("Error cleaning up test. %v\n", err.Error())
}
Expand Down Expand Up @@ -94,13 +94,13 @@ func (s *tableServiceClientLiveTests) TestQueryTable() {
name, _ := getTableName(context, prefix2)
tableNames[i] = name
}
_, err := context.client.Create(ctx, tableNames[i])
_, err := context.client.CreateTable(ctx, tableNames[i])
require.NoError(err)
}

// Query for tables with no pagination. The filter should exclude one table from the results
filter := fmt.Sprintf("TableName ge '%s' and TableName lt '%s'", prefix1, prefix2)
pager := context.client.List(&ListOptions{Filter: &filter})
pager := context.client.ListTables(&ListOptions{Filter: &filter})

resultCount := 0
for pager.NextPage(ctx) {
Expand All @@ -113,7 +113,7 @@ func (s *tableServiceClientLiveTests) TestQueryTable() {

// Query for tables with pagination
top := int32(2)
pager = context.client.List(&ListOptions{Filter: &filter, Top: &top})
pager = context.client.ListTables(&ListOptions{Filter: &filter, Top: &top})

resultCount = 0
pageCount := 0
Expand All @@ -129,11 +129,11 @@ func (s *tableServiceClientLiveTests) TestQueryTable() {
}

func clearAllTables(context *testContext) error {
pager := context.client.List(nil)
pager := context.client.ListTables(nil)
for pager.NextPage(ctx) {
resp := pager.PageResponse()
for _, v := range resp.TableQueryResponse.Value {
_, err := context.client.Delete(ctx, *v.TableName)
_, err := context.client.DeleteTable(ctx, *v.TableName)
if err != nil {
return err
}
Expand All @@ -152,12 +152,12 @@ func (s *tableServiceClientLiveTests) TestListTables() {
require.NoError(err)

for i := 0; i < 5; i++ {
_, err := context.client.Create(ctx, fmt.Sprintf("%v%v", tableName, i))
_, err := context.client.CreateTable(ctx, fmt.Sprintf("%v%v", tableName, i))
require.NoError(err)
}

count := 0
pager := context.client.List(nil)
pager := context.client.ListTables(nil)
for pager.NextPage(ctx) {
resp := pager.PageResponse()
count += len(resp.TableQueryResponse.Value)
Expand Down
6 changes: 3 additions & 3 deletions sdk/tables/aztable/zt_table_recorded_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ func insertNEntities(pk string, n int, client *TableClient) error {
func cleanupTables(context *testContext, tables *[]string) {
c := context.client
if tables == nil {
pager := c.List(nil)
pager := c.ListTables(nil)
for pager.NextPage(ctx) {
for _, t := range pager.PageResponse().TableQueryResponse.Value {
_, err := c.Delete(ctx, *t.TableName)
_, err := c.DeleteTable(ctx, *t.TableName)
if err != nil {
fmt.Printf("Error cleaning up tables. %v\n", err.Error())
}
}
}
} else {
for _, t := range *tables {
_, err := c.Delete(ctx, t)
_, err := c.DeleteTable(ctx, t)
if err != nil {
fmt.Printf("There was an error cleaning up tests. %v\n", err.Error())
}
Expand Down

0 comments on commit e165488

Please sign in to comment.