Skip to content

Commit

Permalink
UI tests: remove tests regarding a read-only registry
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Oct 31, 2023
1 parent a7344bd commit 23d70c6
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions windows-agent/internal/proservices/ui/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,10 @@ func TestGetSubscriptionInfo(t *testing.T) {
wantImmutable bool
wantErr bool
}{
"Success with a non-subscription": {config: mockConfig{source: config.SourceNone}, wantType: none},
"Success with a read-only non-subscription": {config: mockConfig{source: config.SourceNone, registryReadOnly: true}, wantType: none, wantImmutable: true},

"Success with an organization subscription": {config: mockConfig{source: config.SourceRegistry}, wantType: organization},
"Success with a read-only organization subscription": {config: mockConfig{source: config.SourceRegistry, registryReadOnly: true}, wantType: organization, wantImmutable: true},

"Success with a user subscription": {config: mockConfig{source: config.SourceUser}, wantType: user},
"Success with a read-only user subscription": {config: mockConfig{source: config.SourceUser, registryReadOnly: true}, wantType: user, wantImmutable: true},

"Success with a store subscription": {config: mockConfig{source: config.SourceMicrosoftStore}, wantType: store},
"Success with a read-only store subscription": {config: mockConfig{source: config.SourceMicrosoftStore, registryReadOnly: true}, wantType: store, wantImmutable: true},

"Error when the read-only check fails": {config: mockConfig{isReadOnlyErr: true}, wantErr: true},
"Success with a non-subscription": {config: mockConfig{source: config.SourceNone}, wantType: none},
"Success with an organization subscription": {config: mockConfig{source: config.SourceRegistry}, wantType: organization},
"Success with a user subscription": {config: mockConfig{source: config.SourceUser}, wantType: user},
"Success with a store subscription": {config: mockConfig{source: config.SourceMicrosoftStore}, wantType: store},
"Error when the subscription cannot be retreived": {config: mockConfig{subscriptionErr: true}, wantErr: true},
}

Expand Down Expand Up @@ -182,11 +173,10 @@ func TestNotifyPurchase(t *testing.T) {
"Success with a non-subscription": {config: mockConfig{source: config.SourceNone}, wantType: store},
"Success with an existing user subscription": {config: mockConfig{source: config.SourceUser}, wantType: store},

"Error to fetch MS Store": {config: mockConfig{source: config.SourceNone, fetchErr: true}, wantType: none, wantErr: true},
"Error to set the subscription": {config: mockConfig{source: config.SourceNone, setSubscriptionErr: true}, wantType: none, wantErr: true},
"Error to read the registry": {config: mockConfig{source: config.SourceNone, isReadOnlyErr: true}, wantType: none, wantErr: true},
"Error with an existing store subscription": {config: mockConfig{source: config.SourceMicrosoftStore}, wantType: store, wantErr: true},
"Error with a read-only organization subscription": {config: mockConfig{source: config.SourceRegistry, registryReadOnly: true}, wantType: organization, wantImmutable: true, wantErr: true},
"Error to fetch MS Store": {config: mockConfig{source: config.SourceNone, fetchErr: true}, wantType: none, wantErr: true},
"Error to set the subscription": {config: mockConfig{source: config.SourceNone, setSubscriptionErr: true}, wantType: none, wantErr: true},
"Error to read the registry": {config: mockConfig{source: config.SourceNone, subscriptionErr: true}, wantType: none, wantErr: true},
"Error with an existing store subscription": {config: mockConfig{source: config.SourceMicrosoftStore}, wantType: store, wantErr: true},
}

for name, tc := range testCases {
Expand Down Expand Up @@ -214,9 +204,7 @@ func TestNotifyPurchase(t *testing.T) {
}

type mockConfig struct {
registryReadOnly bool // reports registry as read only
setSubscriptionErr bool // Config errors out in SetSubscription function
isReadOnlyErr bool // Config errors out in IsReadOnly function
subscriptionErr bool // Config errors out in Subscription function
fetchErr bool // Config errors out in FetchMicrosoftStoreSubscription function

Expand All @@ -232,26 +220,15 @@ func (m *mockConfig) SetUserSubscription(ctx context.Context, token string) erro
m.source = config.SourceUser
return nil
}
func (m mockConfig) IsReadOnly() (bool, error) {
if m.isReadOnlyErr {
return false, errors.New("IsReadOnly error")
}
return m.registryReadOnly, nil
}

func (m mockConfig) Subscription(context.Context) (string, config.Source, error) {
if m.subscriptionErr {
return "", config.SourceNone, errors.New("Subscription error")
}
return m.token, m.source, nil
}

func (m *mockConfig) FetchMicrosoftStoreSubscription(ctx context.Context) error {
readOnly, err := m.IsReadOnly()
if err != nil {
return err
}
if readOnly {
return errors.New("FetchMicrosoftStoreSubscription found read-only registry")
}
if m.fetchErr {
return errors.New("FetchMicrosoftStoreSubscription error")
}
Expand Down

0 comments on commit 23d70c6

Please sign in to comment.