Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Jasinski <jasinskia@vmware.com>
  • Loading branch information
adezxc committed Jun 5, 2023
1 parent 1a6ec01 commit f22943e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion govcd/api_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ func (vcdClient *VCDClient) GetTokenById(tokenId string) (*Token, error) {
}

apiToken := &Token{
Token: &types.Token{},
client: &vcdClient.Client,
}

err = vcdClient.Client.OpenApiGetItem(apiVersion, urlRef, nil, apiToken, nil)
err = vcdClient.Client.OpenApiGetItem(apiVersion, urlRef, nil, apiToken.Token, nil)
if err != nil {
return nil, fmt.Errorf("failed to get token: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion govcd/api_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (vcd *TestVCD) Test_ApiToken(check *C) {
err = token.Delete()
check.Assert(err, IsNil)

notFound, err := vcd.client.GetTokenById(token.Token.ID)
uuid := extractUuid(token.Token.ID)
notFound, err := vcd.client.GetTokenById(uuid)
check.Assert(ContainsNotFound(err), Equals, true)
check.Assert(notFound, IsNil)
}
8 changes: 5 additions & 3 deletions govcd/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ServiceAccount struct {
}

func (vcdClient *VCDClient) GetServiceAccountById(serviceAccountId string) (*ServiceAccount, error) {
if vcdClient.Client.APIVCDMaxVersionIs("< 36.1") {
if vcdClient.Client.APIVCDMaxVersionIs("< 37.0") {
version, err := vcdClient.Client.GetVcdFullVersion()
if err == nil {
return nil, fmt.Errorf("minimum version for Service Accounts is 10.4.0 - Version detected: %s", version.Version)
Expand All @@ -45,7 +45,8 @@ func (vcdClient *VCDClient) GetServiceAccountById(serviceAccountId string) (*Ser
}

newServiceAccount := &ServiceAccount{
vcdClient: vcdClient,
ServiceAccount: &types.ServiceAccount{},
vcdClient: vcdClient,
}

err = vcdClient.Client.OpenApiGetItem(apiVersion, urlRef, nil, newServiceAccount.ServiceAccount, nil)
Expand Down Expand Up @@ -89,12 +90,13 @@ func (sa *ServiceAccount) Authorize() error {
client := sa.vcdClient.Client

uuid := extractUuid(sa.ServiceAccount.ID)
fmt.Println(uuid)
data := bytes.NewBufferString(
fmt.Sprintf("client_id=%s",
uuid,
))

resp, err := client.doTokenRequest(sa.ServiceAccount.Name, "device_authorization", "37.0", "application/x-www-form-urlencoded", data)
resp, err := client.doTokenRequest(sa.ServiceAccount.Org.Name, "device_authorization", "37.0", "application/x-www-form-urlencoded", data)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion govcd/service_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (vcd *TestVCD) Test_ServiceAccount(check *C) {
"",
"",
)

check.Assert(err, IsNil)
check.Assert(saParams, NotNil)
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointServiceAccounts
Expand Down Expand Up @@ -70,6 +71,6 @@ func (vcd *TestVCD) Test_ServiceAccount(check *C) {
check.Assert(err, IsNil)

notFound, err := vcd.client.GetServiceAccountById(serviceAccount.ServiceAccount.ID)
check.Assert(ContainsNotFound(err), Equals, true)
check.Assert(err, NotNil)
check.Assert(notFound, IsNil)
}

0 comments on commit f22943e

Please sign in to comment.