Skip to content

Commit 7aed078

Browse files
Refactor entitlement helpers
This commit moves the entitlement helpers out of the Run Tasks integration tests into a more generic test helper file.
1 parent 5d5211f commit 7aed078

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

entitlement_helper_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package tfe
5+
6+
import (
7+
"context"
8+
"errors"
9+
)
10+
11+
func getOrgEntitlements(client *Client, organizationName string) (*Entitlements, error) {
12+
ctx := context.Background()
13+
orgEntitlements, err := client.Organizations.ReadEntitlements(ctx, organizationName)
14+
if err != nil {
15+
return nil, err
16+
}
17+
if orgEntitlements == nil {
18+
return nil, errors.New("The organization entitlements are empty.")
19+
}
20+
return orgEntitlements, nil
21+
}
22+
23+
func hasGlobalRunTasks(client *Client, organizationName string) (bool, error) {
24+
oe, err := getOrgEntitlements(client, organizationName)
25+
if err != nil {
26+
return false, err
27+
}
28+
return oe.GlobalRunTasks, nil
29+
}
30+
31+
func hasPrivateRunTasks(client *Client, organizationName string) (bool, error) {
32+
oe, err := getOrgEntitlements(client, organizationName)
33+
if err != nil {
34+
return false, err
35+
}
36+
return oe.PrivateRunTasks, nil
37+
}
38+
39+
func hasAuditLogging(client *Client, organizationName string) (bool, error) {
40+
oe, err := getOrgEntitlements(client, organizationName)
41+
if err != nil {
42+
return false, err
43+
}
44+
return oe.AuditLogging, nil
45+
}

run_task_integration_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,13 @@ package tfe
55

66
import (
77
"context"
8-
"errors"
98
"os"
109
"testing"
1110

1211
"github.com/stretchr/testify/assert"
1312
"github.com/stretchr/testify/require"
1413
)
1514

16-
func getOrgEntitlements(client *Client, organizationName string) (*Entitlements, error) {
17-
ctx := context.Background()
18-
orgEntitlements, err := client.Organizations.ReadEntitlements(ctx, organizationName)
19-
if err != nil {
20-
return nil, err
21-
}
22-
if orgEntitlements == nil {
23-
return nil, errors.New("The organization entitlements are empty.")
24-
}
25-
return orgEntitlements, nil
26-
}
27-
28-
func hasGlobalRunTasks(client *Client, organizationName string) (bool, error) {
29-
oe, err := getOrgEntitlements(client, organizationName)
30-
if err != nil {
31-
return false, err
32-
}
33-
return oe.GlobalRunTasks, nil
34-
}
35-
36-
func hasPrivateRunTasks(client *Client, organizationName string) (bool, error) {
37-
oe, err := getOrgEntitlements(client, organizationName)
38-
if err != nil {
39-
return false, err
40-
}
41-
return oe.PrivateRunTasks, nil
42-
}
43-
4415
func TestRunTasksCreate(t *testing.T) {
4516
client := testClient(t)
4617
ctx := context.Background()

0 commit comments

Comments
 (0)