-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref. #2317 (comment)
- Loading branch information
Showing
9 changed files
with
124 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* | ||
!Gemfile | ||
!Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM ruby:2.6 | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y sudo golang --no-install-recommends | ||
RUN apt-get purge --auto-remove -y curl \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN groupadd -r app && useradd -r -g app -G sudo app \ | ||
&& mkdir -p /home/app && chown -R app:app /home/app | ||
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers | ||
|
||
USER app | ||
|
||
# throw errors if Gemfile has been modified since Gemfile.lock | ||
RUN bundle config --global frozen 1 | ||
|
||
WORKDIR /home/app/workdir | ||
|
||
COPY Gemfile Gemfile.lock ./ | ||
RUN bundle install | ||
|
||
ENV LANG C.UTF-8 | ||
ENV GOFLAGS -mod=vendor | ||
ENV USER app |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Cucumber features for hub | ||
|
||
How to run all features: | ||
|
||
```sh | ||
make bin/cucumber | ||
bin/cucumber | ||
``` | ||
|
||
Because this can take a couple of minutes, you may want to only run select files | ||
related to the functionality that you're developing: | ||
|
||
```sh | ||
bin/cucumber feature/api.feature | ||
``` | ||
|
||
The Cucumber test suite requires a Ruby development environment. If you want to | ||
avoid setting that up, you can run tests inside a Docker container: | ||
|
||
```sh | ||
script/docker feature/api.feature | ||
``` | ||
|
||
## How it works | ||
|
||
Each scenario is actually making real invocations to `hub` on the command-line | ||
in the context of a real (dynamically created) git repository. | ||
|
||
Whenever a scenario requires talking to the GitHub API, a fake HTTP server is | ||
spun locally to replace the real GitHub API. This is done so that the test suite | ||
runs faster and is available offline as well. The fake API server is defined | ||
as a Sinatra app inline in each scenario: | ||
|
||
``` | ||
Given the GitHub API server: | ||
""" | ||
post('/repos/github/hub/pulls') { | ||
status 200 | ||
} | ||
""" | ||
``` | ||
|
||
## How to write new tests | ||
|
||
The best way to learn to write new tests is to study the existing scenarios for | ||
commands that are similar to those that you want to add or change. | ||
|
||
Since Cucumber tests are written in a natural language, you mostly don't need to | ||
know Ruby to write new tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@cache_clear | ||
Feature: hub api | ||
Background: | ||
Given I am "octokitten" on github.com with OAuth token "OTOKEN" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# Usage: script/docker [<cucumber-args>] | ||
set -e | ||
|
||
container=hub-test | ||
workdir=/home/app/workdir | ||
|
||
docker build -t "$container" . | ||
|
||
docker run -it --rm -v "$PWD":"$workdir" -w "$workdir" "$container" \ | ||
/bin/bash -c " | ||
# Enables running WEBrick server (see local_server.rb) | ||
# https://stackoverflow.com/a/45899937/11687 | ||
cp /etc/hosts /tmp/hosts.new \ | ||
&& sed -i 's/::1\\tlocalhost/::1/' /tmp/hosts.new \ | ||
&& sudo cp -f /tmp/hosts.new /etc/hosts || exit 1 | ||
go test ./... | ||
bundle exec cucumber $@ | ||
" |