Skip to content

Commit

Permalink
feat(bin/ofs): Add behavior test for ofs (#4373)
Browse files Browse the repository at this point in the history
* test: ofs

* ci: setup ofs behavior test

* refactor: use public APIs

* fix:  make clippy happy

* chore: remove unused dep
  • Loading branch information
ho-229 authored Apr 9, 2024
1 parent 258f5c7 commit 333029c
Show file tree
Hide file tree
Showing 9 changed files with 527 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .github/actions/test_behavior_bin_ofs/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Test Ofs
description: 'Test Ofs with given setup and service'
inputs:
setup:
description: "The setup action for test"
service:
description: "The service to test"
feature:
description: "The feature to test"

runs:
using: "composite"
steps:
- name: Setup
shell: bash
run: |
mkdir -p ./dynamic_test_bin_ofs &&
cat <<EOF >./dynamic_test_bin_ofs/action.yml
runs:
using: composite
steps:
- name: Setup Test
uses: ./.github/services/${{ inputs.service }}/${{ inputs.setup }}
- name: Run Test Ofs
shell: bash
working-directory: bin/ofs
run: cargo test --features ${{ inputs.feature }} --no-default-features
env:
OPENDAL_TEST: ${{ inputs.service }}
EOF
- name: Run
uses: ./dynamic_test_bin_ofs
40 changes: 39 additions & 1 deletion .github/scripts/test_behavior/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

LANGUAGE_BINDING = ["java", "python", "nodejs"]

BIN = ["ofs"]

def provided_cases() -> list[dict[str, str]]:
root_dir = f"{GITHUB_DIR}/services"
Expand Down Expand Up @@ -82,6 +83,8 @@ class Hint:
binding_python: bool = field(default=False, init=False)
# Is binding nodejs affected?
binding_nodejs: bool = field(default=False, init=False)
# Is bin ofs affected?
bin_ofs: bool = field(default=False, init=False)

# Should we run all services test?
all_service: bool = field(default=False, init=False)
Expand Down Expand Up @@ -137,6 +140,8 @@ def calculate_hint(changed_files: list[str]) -> Hint:
hint.core = True
for language in LANGUAGE_BINDING:
setattr(hint, f"binding_{language}", True)
for bin in BIN:
setattr(hint, f"bin_{bin}", True)
hint.services.add(match.group(1))

# core test affected
Expand All @@ -145,6 +150,8 @@ def calculate_hint(changed_files: list[str]) -> Hint:
hint.core = True
for language in LANGUAGE_BINDING:
setattr(hint, f"binding_{language}", True)
for bin in BIN:
setattr(hint, f"bin_{bin}", True)
hint.services.add(match.group(1))

# fixture affected
Expand All @@ -153,7 +160,14 @@ def calculate_hint(changed_files: list[str]) -> Hint:
hint.core = True
for language in LANGUAGE_BINDING:
setattr(hint, f"binding_{language}", True)
for bin in BIN:
setattr(hint, f"bin_{bin}", True)
hint.services.add(match.group(1))

# bin affected
for bin in BIN:
if p.startswith(f"bin/{bin}"):
setattr(hint, f"bin_{bin}", True)
return hint


Expand Down Expand Up @@ -206,7 +220,7 @@ def generate_language_binding_cases(
if os.getenv("GITHUB_IS_PUSH") == "true":
return cases

# Return empty if core is False
# Return empty if this binding is False
if not getattr(hint, f"binding_{language}"):
return []

Expand All @@ -218,6 +232,23 @@ def generate_language_binding_cases(
cases = [v for v in cases if v["service"] in hint.services]
return cases

def generate_bin_cases(
cases: list[dict[str, str]], hint: Hint, bin: str
) -> list[dict[str, str]]:
cases = unique_cases(cases)

if bin == "ofs":
hint.services.add("fs")
hint.services.add("s3")

# Return empty if this bin is False
if not getattr(hint, f"bin_{bin}"):
return []

# Filter all cases that not shown un in changed files
cases = [v for v in cases if v["service"] in hint.services]
return cases


def plan(changed_files: list[str]) -> dict[str, Any]:
cases = provided_cases()
Expand Down Expand Up @@ -254,6 +285,13 @@ def plan(changed_files: list[str]) -> dict[str, Any]:
jobs["components"][f"binding_{language}"] = True
jobs[f"binding_{language}"].append({"os": "ubuntu-latest", "cases": cases})

for bin in BIN:
jobs[f"bin_{bin}"] = []
jobs["components"][f"bin_{bin}"] = False
cases = generate_bin_cases(cases, hint, bin)
if len(cases) > 0:
jobs["components"][f"bin_{bin}"] = True
jobs[f"bin_{bin}"].append({"os": "ubuntu-latest", "cases": cases})
return jobs


Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/test_behavior.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,16 @@ jobs:
with:
os: ${{ matrix.os }}
cases: ${{ toJson(matrix.cases) }}

test_bin_ofs:
name: bin_ofs / ${{ matrix.os }}
needs: [plan]
if: fromJson(needs.plan.outputs.plan).components.bin_ofs
secrets: inherit
strategy:
matrix:
include: ${{ fromJson(needs.plan.outputs.plan).bin_ofs }}
uses: ./.github/workflows/test_behavior_bin_ofs.yml
with:
os: ${{ matrix.os }}
cases: ${{ toJson(matrix.cases) }}
61 changes: 61 additions & 0 deletions .github/workflows/test_behavior_bin_ofs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Behavior Test Bin Ofs

on:
workflow_call:
inputs:
os:
required: true
type: string
cases:
required: true
type: string

jobs:
test:
name: ${{ matrix.cases.service }} / ${{ matrix.cases.setup }}
runs-on: ${{ inputs.os }}
strategy:
matrix:
cases: ${{ fromJson(inputs.cases) }}
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
need-protoc: true
need-rocksdb: true
github-token: ${{ secrets.GITHUB_TOKEN }}

# TODO: 1password is only supported on linux
#
# Waiting for https://github.com/1Password/load-secrets-action/issues/46
- name: Setup 1Password Connect
if: runner.os == 'Linux'
uses: 1password/load-secrets-action/configure@v1
with:
connect-host: ${{ secrets.OP_CONNECT_HOST }}
connect-token: ${{ secrets.OP_CONNECT_TOKEN }}

- name: Test Bin Ofs
uses: ./.github/actions/test_behavior_bin_ofs
with:
setup: ${{ matrix.cases.setup }}
service: ${{ matrix.cases.service }}
feature: ${{ matrix.cases.feature }}
106 changes: 106 additions & 0 deletions bin/ofs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 333029c

Please sign in to comment.