Skip to content

Commit

Permalink
Add NewListSettingsPager (Azure#19120)
Browse files Browse the repository at this point in the history
* Add NewListSettingsPager

* Re-add changelog headers

* Update coverage goal

Co-authored-by: Anton Kolesnyk <[email protected]>
  • Loading branch information
antkmsft and antkmsft authored Sep 14, 2022
1 parent 9c666b1 commit 4d44597
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion eng/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Packages": [
{
"Name": "azappconfig",
"CoverageGoal": 0.20
"CoverageGoal": 0.19
},
{
"Name": "azblob",
Expand Down
1 change: 1 addition & 0 deletions sdk/data/azappconfig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.4.1 (Unreleased)

### Features Added
* Added `NewListSettingsPager`.

### Breaking Changes

Expand Down
49 changes: 47 additions & 2 deletions sdk/data/azappconfig/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ func fromGeneratedGetRevisionsPage(g generated.AzureAppConfigurationClientGetRev
}
}

// ListRevisionsOptions contains the optional parameters for the ListRevisions method.
// ListRevisionsOptions contains the optional parameters for the NewListRevisionsPager method.
type ListRevisionsOptions struct {
// placeholder for future options
}

// NewListRevisionsPager creates a pager that retrieves the revisions of one or more
// configuration setting entities that match the specified setting selector.
func (c *Client) NewListRevisionsPager(selector SettingSelector, options *ListRevisionsOptions) *runtime.Pager[ListRevisionsPage] {
pagerInternal := c.appConfigClient.NewGetRevisionsPager(selector.toGenerated())
pagerInternal := c.appConfigClient.NewGetRevisionsPager(selector.toGeneratedGetRevisions())
return runtime.NewPager(runtime.PagingHandler[ListRevisionsPage]{
More: func(ListRevisionsPage) bool {
return pagerInternal.More()
Expand All @@ -470,3 +470,48 @@ func (c *Client) NewListRevisionsPager(selector SettingSelector, options *ListRe
},
})
}

// ListSettingsPage contains the configuration settings returned by ListRevisionsPager.
type ListSettingsPage struct {
// Contains the configuration settings returned that match the setting selector provided.
Settings []Setting

// Sync token for the Azure App Configuration client, corresponding to the current state of the client.
SyncToken *string
}

func fromGeneratedGetSettingsPage(g generated.AzureAppConfigurationClientGetKeyValuesResponse) ListSettingsPage {
var css []Setting
for _, cs := range g.Items {
if cs != nil {
css = append(css, settingFromGenerated(*cs))
}
}

return ListSettingsPage{
Settings: css,
SyncToken: g.SyncToken,
}
}

// ListSettingsOptions contains the optional parameters for the NewListSettingsPager method.
type ListSettingsOptions struct {
// placeholder for future options
}

// NewListSettingsPager creates a pager that retrieves setting entities that match the specified setting selector.
func (c *Client) NewListSettingsPager(selector SettingSelector, options *ListSettingsOptions) *runtime.Pager[ListSettingsPage] {
pagerInternal := c.appConfigClient.NewGetKeyValuesPager(selector.toGeneratedGetKeyValues())
return runtime.NewPager(runtime.PagingHandler[ListSettingsPage]{
More: func(ListSettingsPage) bool {
return pagerInternal.More()
},
Fetcher: func(ctx context.Context, cur *ListSettingsPage) (ListSettingsPage, error) {
page, err := pagerInternal.NextPage(ctx)
if err != nil {
return ListSettingsPage{}, err
}
return fromGeneratedGetSettingsPage(page), nil
},
})
}
18 changes: 15 additions & 3 deletions sdk/data/azappconfig/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,28 @@ func TestClient(t *testing.T) {
any := "*"
revPgr := client.NewListRevisionsPager(SettingSelector{KeyFilter: &any, LabelFilter: &any, Fields: AllSettingFields()}, nil)
require.NotEmpty(t, revPgr)
hasMore := revPgr.More()
require.True(t, hasMore)
hasMoreRevs := revPgr.More()
require.True(t, hasMoreRevs)
revResp, err7 := revPgr.NextPage(context.TODO())
require.NoError(t, err7)
require.NotEmpty(t, revResp)
require.Equal(t, key, *revResp.Settings[0].Key)
require.Equal(t, label, *revResp.Settings[0].Label)

delResp, err8 := client.DeleteSetting(context.TODO(), key, &DeleteSettingOptions{Label: &label})
settsPgr := client.NewListSettingsPager(SettingSelector{KeyFilter: &any, LabelFilter: &any, Fields: AllSettingFields()}, nil)
require.NotEmpty(t, settsPgr)
hasMoreSetts := revPgr.More()
require.False(t, hasMoreSetts)
settsResp, err8 := settsPgr.NextPage(context.TODO())
require.NoError(t, err8)
require.NotEmpty(t, settsResp)
require.Equal(t, key, *settsResp.Settings[0].Key)
require.Equal(t, label, *settsResp.Settings[0].Label)
require.Equal(t, value, *settsResp.Settings[0].Value)
require.False(t, *settsResp.Settings[0].IsReadOnly)

delResp, err9 := client.DeleteSetting(context.TODO(), key, &DeleteSettingOptions{Label: &label})
require.NoError(t, err9)
require.NotEmpty(t, delResp)
require.NotNil(t, delResp.Key)
require.NotNil(t, delResp.Label)
Expand Down
22 changes: 21 additions & 1 deletion sdk/data/azappconfig/setting_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func AllSettingFields() []SettingFields {
}
}

func (sc SettingSelector) toGenerated() *generated.AzureAppConfigurationClientGetRevisionsOptions {
func (sc SettingSelector) toGeneratedGetRevisions() *generated.AzureAppConfigurationClientGetRevisionsOptions {
var dt *string
if sc.AcceptDateTime != nil {
str := sc.AcceptDateTime.Format(timeFormat)
Expand All @@ -91,3 +91,23 @@ func (sc SettingSelector) toGenerated() *generated.AzureAppConfigurationClientGe
Select: sf,
}
}

func (sc SettingSelector) toGeneratedGetKeyValues() *generated.AzureAppConfigurationClientGetKeyValuesOptions {
var dt *string
if sc.AcceptDateTime != nil {
str := sc.AcceptDateTime.Format(timeFormat)
dt = &str
}

sf := make([]generated.Get6ItemsItem, len(sc.Fields))
for i := range sc.Fields {
sf[i] = (generated.Get6ItemsItem)(sc.Fields[i])
}

return &generated.AzureAppConfigurationClientGetKeyValuesOptions{
After: dt,
Key: sc.KeyFilter,
Label: sc.LabelFilter,
Select: sf,
}
}

0 comments on commit 4d44597

Please sign in to comment.