Skip to content

Commit

Permalink
Enhance GetTanzuContextActiveResource API to include organization nam…
Browse files Browse the repository at this point in the history
…e retrieval

Signed-off-by: Prem Kumar Kalle <[email protected]>
  • Loading branch information
prkalle committed Apr 26, 2024
1 parent 8822322 commit c3cc92d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ func setupForGetContext() error {
Context: "test-context",
},
AdditionalMetadata: map[string]interface{}{
OrgIDKey: "fake-org-id",
OrgIDKey: "fake-org-id",
OrgNameKey: "fake-org-name",
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions config/tanzu_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const (
type ResourceInfo struct {
// OrgID ID of the Organization
OrgID string
// OrgName name of the Organization
OrgName string
// ProjectName name of the Project
ProjectName string
// ProjectID ID of the Project.
Expand Down Expand Up @@ -321,6 +323,7 @@ func GetTanzuContextActiveResource(contextName string) (*ResourceInfo, error) {
}
activeResourceInfo := &ResourceInfo{
OrgID: stringValue(ctx.AdditionalMetadata[OrgIDKey]),
OrgName: stringValue(ctx.AdditionalMetadata[OrgNameKey]),
ProjectName: stringValue(ctx.AdditionalMetadata[ProjectNameKey]),
ProjectID: stringValue(ctx.AdditionalMetadata[ProjectIDKey]),
SpaceName: stringValue(ctx.AdditionalMetadata[SpaceNameKey]),
Expand Down
4 changes: 4 additions & 0 deletions config/tanzu_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

const (
fakeOrgID = "fake-org-id"
fakeOrgName = "fake-org-name"
fakeProjectName = "fake-project"
fakeProjectID = "fake-project-id"
fakeSpace = "fake-space"
Expand Down Expand Up @@ -226,6 +227,7 @@ func TestGetTanzuContextActiveResource(t *testing.T) {
activeResources, err := GetTanzuContextActiveResource("test-tanzu")
assert.NoError(t, err)
assert.Equal(t, activeResources.OrgID, fakeOrgID)
assert.Equal(t, activeResources.OrgName, fakeOrgName)
assert.Empty(t, activeResources.ProjectName)
assert.Empty(t, activeResources.ProjectID)
assert.Empty(t, activeResources.SpaceName)
Expand All @@ -239,6 +241,7 @@ func TestGetTanzuContextActiveResource(t *testing.T) {
activeResources, err = GetTanzuContextActiveResource("test-tanzu")
assert.NoError(t, err)
assert.Equal(t, activeResources.OrgID, fakeOrgID)
assert.Equal(t, activeResources.OrgName, fakeOrgName)
assert.Equal(t, activeResources.ProjectName, fakeProjectName)
assert.Equal(t, activeResources.ProjectID, fakeProjectID)
assert.Equal(t, activeResources.SpaceName, fakeSpace)
Expand All @@ -254,6 +257,7 @@ func TestGetTanzuContextActiveResource(t *testing.T) {
activeResources, err = GetTanzuContextActiveResource("test-tanzu")
assert.NoError(t, err)
assert.Equal(t, activeResources.OrgID, fakeOrgID)
assert.Equal(t, activeResources.OrgName, fakeOrgName)
assert.Equal(t, activeResources.ProjectName, fakeProjectName)
assert.Equal(t, activeResources.ProjectID, fakeProjectID)
assert.Equal(t, activeResources.ClusterGroupName, fakeClusterGroupName)
Expand Down

0 comments on commit c3cc92d

Please sign in to comment.