forked from Azure/ARO-HCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove cache from SubscriptionStateMuxValidator
* Leverage DBClient instead * Allows us to start deprecating this cache * Stores the entire subscription in the request context * Adds methods to retrieve the subscription state and tenantID from the request context. Signed-off-by: Michael Shen <mshen@redhat.com>
- Loading branch information
Showing
6 changed files
with
130 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package frontend | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Azure/ARO-HCP/internal/api/arm" | ||
) | ||
|
||
func stringPtr(s string) *string { | ||
return &s | ||
} | ||
|
||
func TestTenantIDFromContext(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
sub arm.Subscription | ||
expected string | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "Valid", | ||
sub: arm.Subscription{ | ||
Properties: &arm.Properties{ | ||
TenantId: stringPtr("tenant-id"), | ||
}, | ||
}, | ||
expected: "tenant-id", | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "Missing tenantId", | ||
sub: arm.Subscription{}, | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
ctx := ContextWithSubscription(context.Background(), test.sub) | ||
actual, err := TenantIDFromContext(ctx) | ||
if err != nil { | ||
if !test.expectErr { | ||
t.Errorf("expected err to be nil, got %v", err) | ||
} | ||
} else { | ||
if test.expectErr { | ||
t.Error("expected err to be non-nil") | ||
} | ||
|
||
if actual != test.expected { | ||
t.Errorf("expected %s, got %s", test.expected, actual) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters