Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .github/scripts/azurebs/run-int.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail

script_dir="$( cd "$(dirname "${0}")" && pwd )"
repo_root="$(cd "${script_dir}/../../.." && pwd)"

: "${azure_storage_account:?}"
: "${azure_storage_key:?}"
: "${environment:=AzureCloud}"

export ACCOUNT_NAME="${azure_storage_account}"
export ACCOUNT_KEY="${azure_storage_key}"
export ENVIRONMENT="${environment}"

pushd "${script_dir}" > /dev/null
source utils.sh
container_name="$(read_container_name_from_file "${environment}")"
: "${container_name:?}"
export CONTAINER_NAME="${container_name}"
popd > /dev/null

pushd "${repo_root}" > /dev/null
echo -e "\n running tests with $(go version)..."
ginkgo -r azurebs/integration/
popd > /dev/null

21 changes: 21 additions & 0 deletions .github/scripts/azurebs/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail

script_dir="$( cd "$(dirname "${0}")" && pwd )"
repo_root="$(cd "${script_dir}/../../.." && pwd)"


: "${azure_storage_account:?}"
: "${azure_storage_key:?}"
: "${environment:=AzureCloud}"

export AZURE_STORAGE_ACCOUNT="${azure_storage_account}"
export AZURE_STORAGE_KEY="${azure_storage_key}"



pushd "${script_dir}"
source utils.sh
generate_container_name "${environment}"
create_container "${environment}"
popd
21 changes: 21 additions & 0 deletions .github/scripts/azurebs/teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail

script_dir="$( cd "$(dirname "${0}")" && pwd )"
repo_root="$(cd "${script_dir}/../../.." && pwd)"


: "${azure_storage_account:?}"
: "${azure_storage_key:?}"
: "${environment:=AzureCloud}"

export AZURE_STORAGE_ACCOUNT="${azure_storage_account}"
export AZURE_STORAGE_KEY="${azure_storage_key}"



pushd "${script_dir}"
source utils.sh
delete_container "${environment}"
delete_container_name_file "${environment}"
popd
46 changes: 46 additions & 0 deletions .github/scripts/azurebs/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

TMP_DIR="/tmp/storage-cli-azurebs-${GITHUB_RUN_ID:-${USER}}"

# generate a random container name with "azurebs-" prefix
function random_name {
echo "azurebs-$(openssl rand -hex 20)"
}


# create a file with .lock suffix and store the container name inside it
function generate_container_name {
local file_name="${1}.lock"
local container_name="$(random_name)"
mkdir -p "${TMP_DIR}"
echo "${container_name}" > "${TMP_DIR}/${file_name}"
}


# retrieve the container name from the .lock file
function read_container_name_from_file {
local file_name="$1"
cat "${TMP_DIR}/${file_name}.lock"
}

# delete the .lock file
function delete_container_name_file {
local file_name="$1"
rm -f "${TMP_DIR}/${file_name}.lock"
}


function create_container {
local container_name="$(read_container_name_from_file "$1")"

az storage container create --account-name "${AZURE_STORAGE_ACCOUNT}" --account-key "${AZURE_STORAGE_KEY}" --name "${container_name}"

}


function delete_container {
local container_name="$(read_container_name_from_file "$1")"

az storage container delete --account-name "${AZURE_STORAGE_ACCOUNT}" --account-key "${AZURE_STORAGE_KEY}" --name "${container_name}"

}
42 changes: 42 additions & 0 deletions .github/workflows/azurebs-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Azurebs Integration Tests

on:
workflow_dispatch:
pull_request:
paths:
- ".github/workflows/azurebs-integration.yml"
- "azurebs/**"
push:
branches:
- main

jobs:
azurecloud-environment-integration-tests:
name: AzureCloud Environment Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Install Ginkgo
run: go install github.com/onsi/ginkgo/v2/ginkgo@latest
- name: Setup Azurebs Test Environment
run: |
export azure_storage_account="${{ secrets.AZURE_STORAGE_ACCOUNT }}"
export azure_storage_key="${{ secrets.AZURE_STORAGE_KEY }}"
./.github/scripts/azurebs/setup.sh
- name: Run Tests
run: |
export azure_storage_account="${{ secrets.AZURE_STORAGE_ACCOUNT }}"
export azure_storage_key="${{ secrets.AZURE_STORAGE_KEY }}"
./.github/scripts/azurebs/run-int.sh
- name: Teardown Azurebs Test Environment
if: always()
run: |
export azure_storage_account="${{ secrets.AZURE_STORAGE_ACCOUNT }}"
export azure_storage_key="${{ secrets.AZURE_STORAGE_KEY }}"
./.github/scripts/azurebs/teardown.sh

78 changes: 45 additions & 33 deletions azurebs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Azure Storage CLI

The Azure Storage CLI is for uploading, fetching and deleting content to and from an Azure blobstore.
It is highly inspired by the https://github.com/cloudfoundry/bosh-s3cli.
It is highly inspired by the [storage-cli/s3](https://github.com/cloudfoundry/storage-cli/blob/6058f516e9b81471b64a50b01e228158a05731f0/s3)

## Usage

Expand Down Expand Up @@ -49,35 +49,47 @@ curl -X PUT -H "x-ms-blob-type: blockblob" -F 'fileX=<path/to/file>' <signed url
curl -X GET <signed url>
```

## Running tests

### Unit tests

Using ginkgo:

``` bash
go install github.com/onsi/ginkgo/v2/ginkgo
ginkgo --skip-package=integration --randomize-all --cover -v -r
```

Using go test:

``` bash
go test $(go list ./... | grep -v integration)
```

### Integration tests

1. Export the following variables into your environment:

``` bash
export ACCOUNT_NAME=<your Azure accounnt name>
export ACCOUNT_KEY=<your Azure account key>
export CONTAINER_NAME=<the target container name>
```

2. Run integration tests

```bash
go test ./integration/...
```
## Running Tests

### Unit Tests
**Note:** Run the following commands from the repository root directory

- Using ginkgo:

``` bash
go install github.com/onsi/ginkgo/v2/ginkgo

ginkgo --skip-package=integration --randomize-all --cover -v -r ./azurebs/...
```

- Using go test:

``` bash
go test $(go list ./azurebs/... | grep -v integration)
```

### Integration Tests
- To run the integration tests with your existing container
1. Export the following variables into your environment.

```bash
export ACCOUNT_NAME=<your Azure accounnt name>
export ACCOUNT_KEY=<your Azure account key>
export CONTAINER_NAME=<the target container name>
```

1. Navigate to project's root folder and run the command below:

```bash
go test ./azurebs/integration/...
```

- To run it from scratch; create a new container, run tests, delete the container
1. Create a storage account in your azure subscription.
1. Get `account name` and `access key` from you storage account.
1. Export `account name` with command `export azure_storage_account=<account name>`.
1. Export `access key` with command `export azure_storage_key=<access key>`.
1. Navigate to project's root folder.
1. Run environment setup script to create container `./.github/scripts/azurebs/setup.sh`.
1. Run tests `./.github/scripts/azurebs/run-int.sh`.
1. Run environment teardown script to delete test resources `./.github/scripts/azurebs/teardown.sh`.
2 changes: 1 addition & 1 deletion azurebs/integration/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func AssertPutTimesOut(cliPath string, cfg *config.AZStorageConfig) {
defer os.Remove(configPath) //nolint:errcheck

const mb = 1024 * 1024
big := bytes.Repeat([]byte("x"), 25*mb)
big := bytes.Repeat([]byte("x"), 250*mb)
content := MakeContentFile(string(big))
defer os.Remove(content) //nolint:errcheck
blob := GenerateRandomString()
Expand Down
Loading