Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Google.PowerShell.IntegrationTests/GcloudCmdlets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ function Install-GcloudCmdlets() {
# Creates a GCS bucket owned associated with the project, deleting any existing
# buckets with that name and all of their contents.
function Create-TestBucket($project, $bucket) {
gsutil -m rm -r "gs://${bucket}/*" 2>$null
gsutil rb "gs://${bucket}" 2>$null
gsutil mb -p $project "gs://${bucket}" 2>$null
gcloud storage rm --recursive "gs://${bucket}/*" 2>$null
gcloud storage bucketes delete "gs://${bucket}" 2>$null
gcloud storage buckets create "gs://${bucket}" --project="$project" 2>$null
}

# Copies a 0-byte file from the local machine to Google Cloud Storage.
function Add-TestFile($bucket, $objName) {
$filename = [System.IO.Path]::GetTempFileName()
gsutil ls "gs://${bucket}" 2>$null
gsutil cp $filename "gs://${bucket}/${objName}" 2>$null
gcloud storage ls "gs://${bucket}" 2>$null
gcloud storage cp $filename "gs://${bucket}/${objName}" 2>$null
Remove-Item -Force $filename
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Describe "Remove-GcSqlInstance" {

Describe "Export-GcSqlInstance" {
AfterAll {
gsutil -q rm gs://gcsql-instance-testing/*
gcloud storage rm gs://gcsql-instance-testing/*
}

# For these tests, test-db4 was used because an instance must have a populated database for it to work.
Expand All @@ -181,34 +181,34 @@ Describe "Export-GcSqlInstance" {


It "should export an applicable SQL file" {
$beforeObjects = gsutil ls gs://gcsql-instance-testing
$beforeObjects = gcloud storage ls gs://gcsql-instance-testing
($beforeObjects -contains "gs://gcsql-instance-testing/testsql$r.gz") | Should Be false
Export-GcSqlInstance $instance "gs://gcsql-instance-testing/testsql$r.gz"
$afterObjects = gsutil ls gs://gcsql-instance-testing
$afterObjects = gcloud storage ls gs://gcsql-instance-testing
($afterObjects -contains "gs://gcsql-instance-testing/testsql$r.gz") | Should Be true
}

It "should export an applicable CSV file" {
$beforeObjects = gsutil ls gs://gcsql-instance-testing
$beforeObjects = gcloud storage ls gs://gcsql-instance-testing
($beforeObjects -contains "gs://gcsql-instance-testing/testcsv$r.csv") | Should Be false
Export-GcSqlInstance $instance "gs://gcsql-instance-testing/testcsv$r.csv" "SELECT * FROM guestbook.entries"
$afterObjects = gsutil ls gs://gcsql-instance-testing
$afterObjects = gcloud storage ls gs://gcsql-instance-testing
($afterObjects -contains "gs://gcsql-instance-testing/testcsv$r.csv") | Should Be true
}

It "should be able to export a specific SQL file" {
$beforeObjects = gsutil ls gs://gcsql-instance-testing
$beforeObjects = gcloud storage ls gs://gcsql-instance-testing
($beforeObjects -contains "gs://gcsql-instance-testing/testothersql$r.gz") | Should Be false
Export-GcSqlInstance $instance "gs://gcsql-instance-testing/testothersql$r.gz" -Database "guestbook","guestbook2"
$afterObjects = gsutil ls gs://gcsql-instance-testing
$afterObjects = gcloud storage ls gs://gcsql-instance-testing
($afterObjects -contains "gs://gcsql-instance-testing/testothersql$r.gz") | Should Be true
}

It "should be able to export a specific CSV file" {
$beforeObjects = gsutil ls gs://gcsql-instance-testing
$beforeObjects = gcloud storage ls gs://gcsql-instance-testing
($beforeObjects -contains "gs://gcsql-instance-testing/testothercsv$r.csv") | Should Be false
Export-GcSqlInstance $instance "gs://gcsql-instance-testing/testothercsv$r.csv" -Database "guestbook" "SELECT * FROM entries"
$afterObjects = gsutil ls gs://gcsql-instance-testing
$afterObjects = gcloud storage ls gs://gcsql-instance-testing
($afterObjects -contains "gs://gcsql-instance-testing/testothercsv$r.csv") | Should Be true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Describe "Get-GcsBucket" {
}

It "should work" {
gsutil mb -p gcloud-powershell-testing gs://gcps-testbucket 2>$null
gcloud storage buckets create gs://gcps-testbucket --project gcloud-powershell-testing 2>$null
$bucket = Get-GcsBucket -Name "gcps-testbucket"
$bucket.GetType().FullName | Should Match "Google.Apis.Storage.v1.Data.Bucket"

$bucket.StorageClass | Should Match "STANDARD"
$bucket.Id | Should Match "gcps-testbucket"
$bucket.SelfLink | Should Match "https://www.googleapis.com/storage/v1/b/gcps-testbucket"

gsutil rb gs://gcps-testbucket 2>$null
gcloud storage buckets delete gs://gcps-testbucket 2>$null
}

It "should take into account changes in the Cloud SDK, including environment variables" -Skip:$skipServiceAccountTest {
Expand Down Expand Up @@ -94,12 +94,12 @@ Describe "New-GcsBucket" {

# Should remove the bucket before/after each test to ensure we are in a good state.
BeforeEach {
gsutil -m rm -r "gs://gcps-bucket-creation/*" 2>$null
gsutil rb gs://gcps-bucket-creation 2>$null
gcloud storage rm --recursive "gs://gcps-bucket-creation/*" 2>$null
gcloud storage buckets delete gs://gcps-bucket-creation 2>$null
}

AfterEach {
gsutil rb gs://gcps-bucket-creation 2>$null
gcloud storage buckets delete gs://gcps-bucket-creation 2>$null
}

It "should work" {
Expand Down Expand Up @@ -167,7 +167,7 @@ Describe "New-GcsBucket" {
{ Invoke-WebRequest https://www.googleapis.com/storage/v1/b/gcps-bucket-creation/o/test-obj } |
Should Throw "(401) Unauthorized"
# But going through gsutil (which passes along your Google credentials) will work.
gsutil cat gs://gcps-bucket-creation/test-obj | Should Be "testing 1, 2, 3..."
gcloud storage cat gs://gcps-bucket-creation/test-obj | Should Be "testing 1, 2, 3..."
}
}

Expand Down