Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed Aug 25, 2024
1 parent 4462d73 commit 0626a60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 1 addition & 3 deletions internal/provider/data_source_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
func TestAccDataSourceFolderAttributes(t *testing.T) {
ensureVaultwardenConfigured(t)

resourceName := "bitwarden_folder.foo"

resource.UnitTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
Expand All @@ -19,7 +17,7 @@ func TestAccDataSourceFolderAttributes(t *testing.T) {
},
{
Config: tfConfigProvider() + tfConfigResourceFolder() + tfConfigDataFolder(),
Check: checkObject(resourceName),
Check: checkObject("data.bitwarden_folder.foo_data"),
},
},
})
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/data_source_item_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func TestAccDataSourceItemLoginBySearch(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: tfConfigProvider() + tfConfigResourceItemLogin(),
},
{
Config: tfConfigProvider() + tfConfigResourceItemLogin() + tfConfigDataItemLoginWithSearchAndOrg("test-username"),
Check: checkItemLogin("data.bitwarden_item_login.foo_data"),
Expand Down
17 changes: 14 additions & 3 deletions internal/provider/provider_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func createTestOrganization(t *testing.T) {
func createTestUserResources(t *testing.T) {
testFolderName := fmt.Sprintf("folder-%s-bar", testUniqueIdentifier)
bwClient := bwTestClient(t)
t.Logf("Creating Folder")
folder, err := bwClient.CreateObject(context.Background(), bw.Object{
Object: bw.ObjectTypeFolder,
Name: testFolderName,
Expand Down Expand Up @@ -173,9 +174,19 @@ func bwTestClient(t *testing.T) bw.Client {
}
}
if status.Status == bw.StatusUnauthenticated {
err = client.LoginWithPassword(context.Background(), testEmail, testPassword)
if err != nil {
t.Fatal(err)

retries := 0
for retries < 3 {
err = client.LoginWithPassword(context.Background(), testEmail, testPassword)
if err != nil {
// Retry if the user creation hasn't been fully taken into account yet
if retries < 3 {
retries++
time.Sleep(1 * time.Second)
continue
}
t.Fatal(err)
}
}
} else if status.Status == bw.StatusLocked {
err = client.Unlock(context.Background(), testPassword)
Expand Down

0 comments on commit 0626a60

Please sign in to comment.