mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
Merge branch 'more-advanced-testing' into gitlabci
This commit is contained in:
commit
84aaa2a809
25
.travis.yml
25
.travis.yml
@ -8,8 +8,28 @@ cache:
|
||||
directories:
|
||||
- "node_modules"
|
||||
|
||||
script: npm run test:infrastructure
|
||||
script: npm run test:bundles
|
||||
## Spin up glitlab instance and sleep for 60 seconds
|
||||
before_script:
|
||||
## Spin up container
|
||||
- cd test/docker/
|
||||
- docker-compose -f docker-compose.test.yml up -d
|
||||
- cd .
|
||||
|
||||
## Get the docker env variables
|
||||
- export PERSONAL_ACCESS_TOKEN=$(docker exec -i gitlab echo PERSONAL_ACCESS_TOKEN)
|
||||
- export GITLAB_URL=$(docker exec -i gitlab echo GITLAB_URL)
|
||||
|
||||
## Sleep before performing commands on container
|
||||
- sleep 30
|
||||
|
||||
## run tests
|
||||
script:
|
||||
- npm run test:infrastructure
|
||||
- npm run test:bundles
|
||||
- npm run test:services
|
||||
|
||||
after_script:
|
||||
- docker-compose -f docker-compose.test.yml down
|
||||
|
||||
jobs:
|
||||
include:
|
||||
@ -17,4 +37,3 @@ jobs:
|
||||
script: npm run lint
|
||||
- stage: build
|
||||
script: npm run build
|
||||
# script: npm run test:services
|
||||
@ -1,7 +0,0 @@
|
||||
version: '2'
|
||||
services:
|
||||
gitlab:
|
||||
image: gitlab/gitlab-ce
|
||||
ports:
|
||||
- 8080:80
|
||||
- 8443:443
|
||||
6146
package-lock.json
generated
6146
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
36
package.json
36
package.json
@ -12,11 +12,10 @@
|
||||
"build:es5": "babel src -d dist/es5 --config-file=./.babelrc-es5",
|
||||
"build": "npm run build:clean && npm run build:es6 && npm run build:es5",
|
||||
"lint": "node_modules/.bin/eslint ./src ./tests",
|
||||
"test:bundles": "jest tests/bundles",
|
||||
"test:infrastructure": "jest tests/infrastructure",
|
||||
"test:services": "jest tests/services",
|
||||
"test:bundles": "jest test/tests/bundles",
|
||||
"test:infrastructure": "jest test/tests/infrastructure",
|
||||
"test:services": "jest test/tests/services",
|
||||
"test": "jest && codecov",
|
||||
"test:watch": "GITLAB_URL=http://localhost:8080 API_TOKEN=ysccjxQtMCqz_wBfJEy2 jest --watch",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"repository": {
|
||||
@ -34,31 +33,32 @@
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0-beta.46",
|
||||
"@babel/core": "^7.0.0-beta.46",
|
||||
"@babel/plugin-proposal-export-default-from": "^7.0.0-beta.46",
|
||||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0-beta.46",
|
||||
"@babel/plugin-transform-runtime": "^7.0.0-beta.46",
|
||||
"@babel/preset-env": "^7.0.0-beta.46",
|
||||
"@babel/cli": "^7.0.0-beta.47",
|
||||
"@babel/core": "^7.0.0-beta.47",
|
||||
"@babel/plugin-proposal-export-default-from": "^7.0.0-beta.47",
|
||||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0-beta.47",
|
||||
"@babel/plugin-transform-runtime": "^7.0.0-beta.47",
|
||||
"@babel/preset-env": "^7.0.0-beta.47",
|
||||
"babel-core": "^7.0.0-0",
|
||||
"babel-eslint": "^8.2.3",
|
||||
"babel-jest": "^23.0.0-alpha.0",
|
||||
"eslint": "^5.0.0-alpha.2",
|
||||
"babel-jest": "^22.4.3",
|
||||
"eslint": "^5.0.0-alpha.3",
|
||||
"eslint-config-airbnb": "^16.1.0",
|
||||
"eslint-plugin-import": "^2.11.0",
|
||||
"eslint-plugin-jest": "^21.15.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.0.3",
|
||||
"eslint-plugin-react": "^7.7.0",
|
||||
"jest": "^23.0.0-charlie.1",
|
||||
"jest-tap-reporter": "^1.9.0"
|
||||
"eslint-plugin-react": "^7.8.2",
|
||||
"jest": "^22.4.3",
|
||||
"jest-tap-reporter": "^1.9.0",
|
||||
"regenerator-runtime": "^0.11.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0-beta.46",
|
||||
"@babel/runtime": "^7.0.0-beta.47",
|
||||
"humps": "^2.0.1",
|
||||
"jest": "^23.0.0-alpha.4",
|
||||
"lodash.pick": "^4.4.0",
|
||||
"parse-link-header": "^1.0.1",
|
||||
"qs": "^6.5.2",
|
||||
"request": "^2.85.0",
|
||||
"request": "^2.86.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"request-promise-core": "^1.1.1",
|
||||
"url-join": "^4.0.0",
|
||||
|
||||
16
test/docker/docker-compose.test.yml
Normal file
16
test/docker/docker-compose.test.yml
Normal file
@ -0,0 +1,16 @@
|
||||
version: '3'
|
||||
services:
|
||||
gitlab:
|
||||
image: gitlab/gitlab-ce
|
||||
container_name: gitlab
|
||||
entrypoint: init/docker-entrypoint
|
||||
environment:
|
||||
- GITLAB_URL='http://localhost:8080'
|
||||
- PERSONAL_ACCESS_TOKEN='token'
|
||||
ports:
|
||||
- 8080:80
|
||||
- 8443:443
|
||||
volumes:
|
||||
- ./docker-entrypoint:/init/docker-entrypoint
|
||||
- ./init:/init/init
|
||||
- ./test.rb:/init/test.rb
|
||||
14
test/docker/docker-entrypoint
Executable file
14
test/docker/docker-entrypoint
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Running the init logic for gitlab. See PR# for splitting this wrapper file into two pieces
|
||||
/bin/bash init/init &>/dev/null
|
||||
|
||||
echo Sleep for 30 seconds to ensure all services are running
|
||||
sleep 30
|
||||
|
||||
echo Initalize test token and user
|
||||
PERSONAL_ACCESS_TOKEN="$(gitlab-rails r /init/test.rb)"
|
||||
|
||||
echo Tail and wait
|
||||
gitlab-ctl tail&
|
||||
wait
|
||||
101
test/docker/init
Normal file
101
test/docker/init
Normal file
@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
function sigterm_handler() {
|
||||
echo "SIGTERM signal received, try to gracefully shutdown all services..."
|
||||
gitlab-ctl stop
|
||||
}
|
||||
|
||||
function failed_pg_upgrade() {
|
||||
echo 'Upgrading the existing database to 9.6 failed and was reverted.'
|
||||
echo 'Please check the output, and open an issue at:'
|
||||
echo 'https://gitlab.com/gitlab-org/omnibus-gitlab/issues'
|
||||
echo 'If you would like to restart the instance without attempting to'
|
||||
echo 'upgrade, add the following to your docker command:'
|
||||
echo '-e GITLAB_SKIP_PG_UPGRADE=true'
|
||||
exit 1
|
||||
}
|
||||
|
||||
trap "sigterm_handler; exit" TERM
|
||||
|
||||
source /RELEASE
|
||||
echo "Thank you for using GitLab Docker Image!"
|
||||
echo "Current version: $RELEASE_PACKAGE=$RELEASE_VERSION"
|
||||
echo ""
|
||||
if [[ "$PACKAGECLOUD_REPO" == "unstable" ]]; then
|
||||
echo "You are using UNSTABLE version of $RELEASE_PACKAGE!"
|
||||
echo ""
|
||||
fi
|
||||
echo "Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file"
|
||||
echo "And restart this container to reload settings."
|
||||
echo "To do it use docker exec:"
|
||||
echo
|
||||
echo " docker exec -it gitlab vim /etc/gitlab/gitlab.rb"
|
||||
echo " docker restart gitlab"
|
||||
echo
|
||||
echo "For a comprehensive list of configuration options please see the Omnibus GitLab readme"
|
||||
echo "https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md"
|
||||
echo
|
||||
echo "If this container fails to start due to permission problems try to fix it by executing:"
|
||||
echo
|
||||
echo " docker exec -it gitlab update-permissions"
|
||||
echo " docker restart gitlab"
|
||||
echo
|
||||
sleep 3s
|
||||
|
||||
# Copy gitlab.rb for the first time
|
||||
if [[ ! -e /etc/gitlab/gitlab.rb ]]; then
|
||||
echo "Installing gitlab.rb config..."
|
||||
cp /opt/gitlab/etc/gitlab.rb.template /etc/gitlab/gitlab.rb
|
||||
chmod 0600 /etc/gitlab/gitlab.rb
|
||||
fi
|
||||
|
||||
# Generate ssh host key for the first time
|
||||
if [[ ! -f /etc/gitlab/ssh_host_rsa_key ]]; then
|
||||
echo "Generating ssh_host_rsa_key..."
|
||||
ssh-keygen -f /etc/gitlab/ssh_host_rsa_key -N '' -t rsa
|
||||
chmod 0600 /etc/gitlab/ssh_host_rsa_key
|
||||
fi
|
||||
if [[ ! -f /etc/gitlab/ssh_host_ecdsa_key ]]; then
|
||||
echo "Generating ssh_host_ecdsa_key..."
|
||||
ssh-keygen -f /etc/gitlab/ssh_host_ecdsa_key -N '' -t ecdsa
|
||||
chmod 0600 /etc/gitlab/ssh_host_ecdsa_key
|
||||
fi
|
||||
if [[ ! -f /etc/gitlab/ssh_host_ed25519_key ]]; then
|
||||
echo "Generating ssh_host_ed25519_key..."
|
||||
ssh-keygen -f /etc/gitlab/ssh_host_ed25519_key -N '' -t ed25519
|
||||
chmod 0600 /etc/gitlab/ssh_host_ed25519_key
|
||||
fi
|
||||
|
||||
# Remove all services, the reconfigure will create them
|
||||
echo "Preparing services..."
|
||||
rm -f /opt/gitlab/service/*
|
||||
ln -s /opt/gitlab/sv/sshd /opt/gitlab/service
|
||||
ln -sf /opt/gitlab/embedded/bin/sv /opt/gitlab/init/sshd
|
||||
mkdir -p /var/log/gitlab/sshd
|
||||
|
||||
# Start service manager
|
||||
echo "Starting services..."
|
||||
GITLAB_OMNIBUS_CONFIG= /opt/gitlab/embedded/bin/runsvdir-start &
|
||||
|
||||
# Configure gitlab package
|
||||
# WARNING:
|
||||
# the preinst script has the database backup
|
||||
# It will not be executed, because all services are not yet started
|
||||
# They will be started when `reconfigure` is executed
|
||||
echo "Configuring GitLab package..."
|
||||
/var/lib/dpkg/info/${RELEASE_PACKAGE}.preinst upgrade
|
||||
|
||||
echo "Configuring GitLab..."
|
||||
gitlab-ctl reconfigure
|
||||
|
||||
# Make sure PostgreSQL is at the latest version.
|
||||
# If it fails, print a message with a workaround and exit
|
||||
if [ "${GITLAB_SKIP_PG_UPGRADE}" != true ]; then
|
||||
gitlab-ctl pg-upgrade -w || failed_pg_upgrade
|
||||
fi
|
||||
|
||||
if [ -n "${GITLAB_POST_RECONFIGURE_SCRIPT+x}" ]; then
|
||||
echo "Runnning Post Reconfigure Script..."
|
||||
eval "${GITLAB_POST_RECONFIGURE_SCRIPT}"
|
||||
fi
|
||||
11
test/docker/test.rb
Normal file
11
test/docker/test.rb
Normal file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env ruby
|
||||
u = User.first
|
||||
u.password_automatically_set = false
|
||||
u.password = 'password'
|
||||
u.password_confirmation = 'password'
|
||||
u.save!
|
||||
|
||||
t = PersonalAccessToken.new({ user: u, name: 'node-gitlab', scopes: ['api']})
|
||||
t.save!
|
||||
|
||||
puts t.token
|
||||
@ -1,8 +1,8 @@
|
||||
import { GroupsBundle } from '../../src';
|
||||
import Services from '../../src/services';
|
||||
import { GroupsBundle } from '../../../src';
|
||||
import * as Services from '../../../src/services';
|
||||
|
||||
test('All the correct service keys are included in the groups bundle', async () => {
|
||||
const bundle = new GroupsBundle();
|
||||
const bundle = new GroupsBundle({ token: 'test' });
|
||||
const services = [
|
||||
'Groups',
|
||||
'GroupAccessRequests',
|
||||
@ -23,7 +23,7 @@ test('All the correct service keys are included in the groups bundle', async ()
|
||||
});
|
||||
|
||||
test('All the correct service instances are included in the groups bundle', async () => {
|
||||
const bundle = new GroupsBundle();
|
||||
const bundle = new GroupsBundle({ token: 'test' });
|
||||
|
||||
Object.keys(bundle).forEach((key) => {
|
||||
expect(bundle[key]).instanceOf(Services[key]);
|
||||
@ -1,8 +1,8 @@
|
||||
import { ProjectsBundle } from '../../src';
|
||||
import Services from '../../src/services';
|
||||
import { ProjectsBundle } from '../../../src';
|
||||
import * as Services from '../../../src/services';
|
||||
|
||||
test('All the correct service keys are included in the projects bundle', async () => {
|
||||
const bundle = new ProjectsBundle();
|
||||
const bundle = new ProjectsBundle({ token: 'test' });
|
||||
const services = [
|
||||
'Branches',
|
||||
'Commits',
|
||||
@ -48,7 +48,7 @@ test('All the correct service keys are included in the projects bundle', async (
|
||||
});
|
||||
|
||||
test('All the correct service instances are included in the projects bundle', async () => {
|
||||
const bundle = new ProjectsBundle();
|
||||
const bundle = new ProjectsBundle({ token: 'test' });
|
||||
|
||||
Object.keys(bundle).forEach((key) => {
|
||||
expect(bundle[key]).instanceOf(Services[key]);
|
||||
@ -1,15 +1,15 @@
|
||||
import { UsersBundle } from '../../src';
|
||||
import Services from '../../src/services';
|
||||
import { UsersBundle } from '../../../src';
|
||||
import * as Services from '../../../src/services';
|
||||
|
||||
test('All the correct service keys are included in the users bundle', async () => {
|
||||
const bundle = new UsersBundle();
|
||||
const bundle = new UsersBundle({ token: 'test' });
|
||||
const services = ['Users', 'UserEmails', 'UserImpersonationTokens', 'UserKeys', 'UserGPGKeys'];
|
||||
|
||||
expect(bundle).toHaveProperty(services);
|
||||
});
|
||||
|
||||
test('All the correct service instances are included in the users bundle', async () => {
|
||||
const bundle = new UsersBundle();
|
||||
const bundle = new UsersBundle({ token: 'test' });
|
||||
|
||||
Object.keys(bundle).forEach((key) => {
|
||||
expect(bundle[key]).instanceOf(Services[key]);
|
||||
@ -1,4 +1,4 @@
|
||||
import { BaseService } from '../../src/infrastructure';
|
||||
import { BaseService } from '../../../src/infrastructure';
|
||||
|
||||
describe('Creation of BaseService instance', () => {
|
||||
test('If a token or oauthToken is not passed, throw an error', async () => {
|
||||
@ -1,4 +1,4 @@
|
||||
import { Bundler } from '../../src/infrastructure';
|
||||
import { Bundler } from '../../../src/infrastructure';
|
||||
|
||||
class Test1 {
|
||||
constructor(value) {
|
||||
15
test/tests/services/Projects.js
Normal file
15
test/tests/services/Projects.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { Projects } from '../../../src';
|
||||
|
||||
const credentials = {
|
||||
url: process.env.GITLAB_URL,
|
||||
token: process.env.PERSONAL_ACCESS_TOKEN
|
||||
}
|
||||
|
||||
describe('Projects.all', () => {
|
||||
it('should return empty array', async () => {
|
||||
const service = new Projects(credentials);
|
||||
const projects = await service.all();
|
||||
|
||||
expect(projects).toEqual([]);
|
||||
});
|
||||
});
|
||||
@ -1,10 +0,0 @@
|
||||
import { Projects } from '../../src';
|
||||
|
||||
describe('Projects.all', () => {
|
||||
it('should return empty array', async () => {
|
||||
const service = new Projects({ url: process.env.GITLAB_URL, token: process.env.API_TOKEN });
|
||||
const projects = await service.all();
|
||||
|
||||
expect(projects).toEqual([]);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user