| 1 |
package paths |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage" |
| 9 |
"github.com/tombuildsstuff/giovanni/storage/2018-11-09/datalakestore/filesystems" |
| 10 |
"github.com/tombuildsstuff/giovanni/testhelpers" |
| 11 |
) |
| 12 |
|
| 13 |
func TestLifecycle(t *testing.T) { |
| 14 |
|
| 15 |
const defaultACLString = "user::rwx,group::r-x,other::---" |
| 16 |
|
| 17 |
client, err := testhelpers.Build(t) |
| 18 |
if err != nil { |
| 19 |
t.Fatal(err) |
| 20 |
} |
| 21 |
ctx := context.TODO() |
| 22 |
|
| 23 |
resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt()) |
| 24 |
accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString()) |
| 25 |
fileSystemName := fmt.Sprintf("acctestfs-%s", testhelpers.RandomString()) |
| 26 |
path := "test" |
| 27 |
|
| •28 |
if _, err = client.BuildTestResourcesWithHns(ctx, resourceGroup, accountName, storage.BlobStorage); err != nil { |
| 29 |
t.Fatal(err) |
| 30 |
} |
| 31 |
defer client.DestroyTestResources(ctx, resourceGroup, accountName) |
| 32 |
fileSystemsClient := filesystems.NewWithEnvironment(client.Environment) |
| 33 |
fileSystemsClient.Client = client.PrepareWithStorageResourceManagerAuth(fileSystemsClient.Client) |
| 34 |
pathsClient := NewWithEnvironment(client.Environment) |
| 35 |
pathsClient.Client = client.PrepareWithStorageResourceManagerAuth(fileSystemsClient.Client) |
| 36 |
|
| 37 |
t.Logf("[DEBUG] Creating an empty File System..") |
| 38 |
fileSystemInput := filesystems.CreateInput{} |
| 39 |
if _, err = fileSystemsClient.Create(ctx, accountName, fileSystemName, fileSystemInput); err != nil { |
| 40 |
t.Fatal(fmt.Errorf("Error creating: %s", err)) |
| 41 |
} |
| 42 |
|
| 43 |
t.Logf("[DEBUG] Creating folder 'test' ..") |
| 44 |
input := CreateInput{ |
| 45 |
Resource: PathResourceDirectory, |
| 46 |
} |
| 47 |
if _, err = pathsClient.Create(ctx, accountName, fileSystemName, path, input); err != nil { |
| 48 |
t.Fatal(fmt.Errorf("Error creating: %s", err)) |
| 49 |
} |
| 50 |
|
| 51 |
t.Logf("[DEBUG] Getting properties for folder 'test' ..") |
| 52 |
props, err := pathsClient.GetProperties(ctx, accountName, fileSystemName, path, GetPropertiesActionGetAccessControl) |
| 53 |
if err != nil { |
| 54 |
t.Fatal(fmt.Errorf("Error getting properties: %s", err)) |
| 55 |
} |
| 56 |
t.Logf("[DEBUG] Props.Owner: %q", props.Owner) |
| 57 |
t.Logf("[DEBUG] Props.Group: %q", props.Group) |
| 58 |
t.Logf("[DEBUG] Props.ACL: %q", props.ACL) |
| 59 |
t.Logf("[DEBUG] Props.ETag: %q", props.ETag) |
| 60 |
t.Logf("[DEBUG] Props.LastModified: %q", props.LastModified) |
| 61 |
if props.ACL != defaultACLString { |
| 62 |
t.Fatal(fmt.Errorf("Expected Default ACL %q, got %q", defaultACLString, props.ACL)) |
| 63 |
} |
| 64 |
|
| 65 |
newACL := "user::rwx,group::r-x,other::r-x,default:user::rwx,default:group::r-x,default:other::---" |
| 66 |
accessControlInput := SetAccessControlInput{ |
| 67 |
ACL: &newACL, |
| 68 |
} |
| 69 |
t.Logf("[DEBUG] Setting Access Control for folder 'test' ..") |
| 70 |
if _, err = pathsClient.SetAccessControl(ctx, accountName, fileSystemName, path, accessControlInput); err != nil { |
| 71 |
t.Fatal(fmt.Errorf("Error setting Access Control %s", err)) |
| 72 |
} |
| 73 |
|
| 74 |
t.Logf("[DEBUG] Getting properties for folder 'test' (2) ..") |
| 75 |
props, err = pathsClient.GetProperties(ctx, accountName, fileSystemName, path, GetPropertiesActionGetAccessControl) |
| 76 |
if err != nil { |
| 77 |
t.Fatal(fmt.Errorf("Error getting properties (2): %s", err)) |
| 78 |
} |
| 79 |
if props.ACL != newACL { |
| 80 |
t.Fatal(fmt.Errorf("Expected new ACL %q, got %q", newACL, props.ACL)) |
| 81 |
} |
| 82 |
|
| 83 |
t.Logf("[DEBUG] Deleting path 'test' ..") |
| 84 |
if _, err = pathsClient.Delete(ctx, accountName, fileSystemName, path); err != nil { |
| 85 |
t.Fatal(fmt.Errorf("Error deleting path: %s", err)) |
| 86 |
} |
| 87 |
|
| 88 |
t.Logf("[DEBUG] Getting properties for folder 'test' (3) ..") |
| 89 |
props, err = pathsClient.GetProperties(ctx, accountName, fileSystemName, path, GetPropertiesActionGetAccessControl) |
| 90 |
if err == nil { |
| 91 |
t.Fatal(fmt.Errorf("Didn't get error getting properties after deleting path (3)")) |
| 92 |
} |
| 93 |
|
| 94 |
t.Logf("[DEBUG] Deleting File System..") |
| 95 |
if _, err := fileSystemsClient.Delete(ctx, accountName, fileSystemName); err != nil { |
| 96 |
t.Fatalf("Error deleting filesystem: %s", err) |
| 97 |
} |
| 98 |
} |