Skip to content

Commit

Permalink
Implement BDD tests (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuncar authored Sep 11, 2020
1 parent 8a84a06 commit e397bbf
Show file tree
Hide file tree
Showing 742 changed files with 5,460 additions and 42,048 deletions.
2 changes: 2 additions & 0 deletions .generated_files
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docs/v[1-9][0-9]*/
lib/datadog_api_client/v[1-9][0-9]*/
12 changes: 12 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See https://help.github.com/articles/about-codeowners/ for syntax
# Rules are matched bottom-to-top, so one team can own subdirectories
# and another team can own the rest of the directory.

# All your base
* @DataDog/integrations-tools-and-libraries

# Documentation
*.md @DataDog/baklava @DataDog/integrations-tools-and-libraries
LICENSE @DataDog/baklava @DataDog/integrations-tools-and-libraries
NOTICE @DataDog/baklava @DataDog/integrations-tools-and-libraries
LICENSE-3rdparty.csv @DataDog/baklava @DataDog/integrations-tools-and-libraries
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'kind/bug'
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

Label the issue properly.
- Add `severity/` label.
- Add `documentation` label if this issue is related to documentation changes.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment and Versions (please complete the following information):**
A clear and precise description of your setup:
- version for this project in use.
- services, libraries, languages and tools list and versions.

**Additional context**
Add any other context about the problem here.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Datadog Support
url: https://www.datadoghq.com/support/
about: Our friendly, knowledgeable support engineers are here to help.
- name: Datadog Security
url: https://www.datadoghq.com/security/
about: We care about security. If you have any questions, or encounter any issues, please contact us.
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'kind/feature-request'
assignees: ''

---

**Note:**
If you have a feature request, you should [contact support](https://docs.datadoghq.com/help/) so the request can be properly tracked.

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
39 changes: 39 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
** Requirements for Contributing to this repository **
* Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely
manner may be closed at the maintainers' discretion.
* After you create the pull request, all status checks must be pass before a maintainer reviews your contribution.
For more details, please see [CONTRIBUTING](/CONTRIBUTING.md).
-->

### What does this PR do?

<!--
What inspired you to submit this pull request?
Link to the issue describing the bug that you're fixing.
If there is not yet an issue for your bug, please open a new issue and then link to that issue in your pull request.
Note: In some cases, one person's "bug" is another person's "feature."
If the pull request does not address an existing issue with the "bug" label, the maintainers have the final say on whether the current behavior is a bug.
We must be able to understand the design of your change from this description.
If we can't get a good idea of what the code will be doing from the description here, the pull request may be closed at the maintainers' discretion.
Keep in mind that the maintainer reviewing this PR may not be familiar with or have worked with the code here recently, so please walk us through the concepts.
-->

### Additional Notes

<!-- Anything else we should know when reviewing? -->

### Review checklist
Please check relevant items below:
- [ ] This PR includes all [newly recorded cassettes](/DEVELOPMENT.md) for any modified tests.


- [ ] This PR does not rely on API client schema changes.
- [ ] The CI should be fully passing.
- [ ] Or, this PR relies on API schema changes and this is a Draft PR to include tests for that new functionality.
- Note: CI shouldn't be run on this Draft PR, as its expected to fail without the corresponding schema changes.
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Configuration for labeler - https://github.com/actions/labeler

documentation: "**/*.md"
21 changes: 21 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Ensure labels"
on: # yamllint disable-line rule:truthy
pull_request:
types:
- labeled
- unlabeled
- opened
- synchronize
- reopened

jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Check changelog labels
if: false == contains(join(github.event.pull_request.labels.*.name, ','), 'changelog/')
run: |-
echo "::error Add 'changelog/*' label";
exit 1;
- name: OK
run: echo "Thank you!"
11 changes: 11 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Pull Request Labeler"
on:
- pull_request

jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: DataDog/labeler@glob-all
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
39 changes: 39 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Configuration for https://github.com/actions/stale

name: "Stale issues and pull requests"
on:
schedule:
- cron: "0 0 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: >-
Thanks for your contribution!
This issue has been automatically marked as stale because it has not had
activity in the last 30 days. Note that the issue will not be automatically
closed, but this notification will remind us to investigate why there's
been inactivity. Thank you for participating in the Datadog open source community.
If you would like this issue to remain open:
1. Verify that you can still reproduce the issue in the latest version of this project.
1. Comment that the issue is still reproducible and include updated details requested in the issue template.
days-before-stale: 30
days-before-close: 99999
stale-issue-label: 'stale'
exempt-issue-label: 'stale/exempt'
stale-pr-message: >-
This issue has been automatically marked as stale because it has not had activity in the last 30 days.
Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity.
stale-pr-label: 'stale'
exempt-pr-label: 'stale/exempt'
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Run Tests

on:
pull_request:
branches:
- master

jobs:
pre-commit:
runs-on: ubuntu-latest
if: false == startsWith(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && !contains(github.event.pull_request.labels.*.name, 'ci/skip/pre-commit')
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- name: Install pre-commit
run: python -m pip install pre-commit
- name: set PY
run: echo "::set-env name=PY::$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')"
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: pre-commit run --all-files --source ${{ github.event.pull_request.base.sha }} --origin ${{ github.event.pull_request.head.sha }} --show-diff-on-failure --color=always

test:
strategy:
matrix:
ruby-version: ['2.5', '2.6', '2.7']
platform: [ubuntu-latest, macos-latest, windows-latest]
# test only latest version on macos and windows
exclude:
- platform: macos-latest
ruby-version: '2.5'
- platform: macos-latest
ruby-version: '2.6'
- platform: windows-latest
ruby-version: '2.5'
- platform: windows-latest
ruby-version: '2.6'
runs-on: ${{ matrix.platform }}
if: github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')
steps:
- uses: actions/checkout@v2
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: actions/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Install
run: bundle install
- name: Test
run: ./run-tests.sh
shell: bash
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.bundle
Gemfile.lock
rerun.txt
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: local
hooks:
- id: generated
name: Do not commit generated files
language: fail
entry: Unstage generated files with 'git reset --' command
files: '^lib/datadog_api_client/v[1-9].*'
verbose: true
- id: generated-features
name: Do not commit generated feature files
language: fail
entry: Unstage generated files with 'git reset --' command
files: '^features/v[1-9][0-9]*/.*.feature$'
verbose: true
38 changes: 38 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Development

This repository contains code that is autogenerated via the
[openapi-generator](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/ruby) project.

As such, this repository should only contain development for adding or fixing tests, for improving development tooling and documentation

## Testing

### Prerequisite

Export the following environment variables:
* `DD_TEST_CLIENT_API_KEY`: The Datadog API key to run integration tests against
* `DD_TEST_CLIENT_APP_KEY`: The Datadog Application key to run integration tests against

**IMPORTANT**: Do not use production keys.

<!---
Tests can be run againts different site (EU, staging, local):
* `DD_TEST_SITE`: The base URL for test site (e.g. `datadoghq.eu`)
**NOTE**: All recorded URLs will be replaced by `datadoghq.com`. Please make sure that you do NOT leak any
any sensitive information.
--->

### Commands

This project contains BDD tests.
__Never__ run the test suite against an organization with production data.

Tests can be executed via [`cucumber`](https://cucumber.io/docs/guides/).
You can optionally add `features/v<NUMBER>/<FILENAME>.feature:<LINE_NUMBER>` to filter individual tests.

By default integration tests use recorded API responses stored in cassettes. To record new API responses run the tests with `RECORD=true`. To run integration tests against API without recording cassettes, run the tests with `RECORD=none`.

**IMPORTANT**:
When creating a PR that adds or updates a test, __never__ commit
generated code, only commit test files being updated and any updated cassettes.
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN bundle install && \
gem install ./datadog_api_client.gem


CMD ["./run-tests.sh"]
CMD ["/datadog-api-client-ruby/run-tests.sh"]
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ group :development, :test do
gem 'reek'
gem 'rspec-expectations'
gem 'solargraph'
gem 'timecop'
gem 'webmock'
end
4 changes: 1 addition & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'

Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "--format pretty --tags \"not @smoke and not @skip\"" # Any valid command line option can go here.
end
Cucumber::Rake::Task.new(:features)
Loading

0 comments on commit e397bbf

Please sign in to comment.