Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test docker sqoop #10

Merged
merged 23 commits into from
Jan 11, 2017
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
15 changes: 14 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
{
"presets": ["latest"]
"presets": [
"latest"
],
"plugins": [
[
"transform-runtime",
{
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}
]
]
}
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
sudo: required

services:
- docker

language: node_js

node_js:
Expand All @@ -6,5 +11,8 @@ node_js:
- "5"
- "4"

before_install:
- docker run -d -p 12000:12000 jimexist/sqoop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得暂时还用不到 cache 吧…… load 这个 image 会很慢么?


script:
npm run coverage
npm run coverage
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-latest": "^6.16.0",
"chai": "^3.5.0",
"coveralls": "^2.11.15",
Expand Down
33 changes: 32 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,39 @@
* Created by Chyroc on 17/1/10.
*/

import { sendGetRequest } from './utils/sendRequest'

import url from 'url'
import path from 'path'
import querystring from 'querystring'

export class Hasoop {
constructor (config) {
this.config = config
this.userName = config.userName
this.host = config.host
this.port = config.port
this.weapp = config.webapp

this.versionUri = 'version'
}

formatUrl ([basicPath, queryObject = {}], ...otherPath) {
queryObject['user.name'] = this.userName
const urlQuery = querystring.stringify(queryObject)
const urlPath = path.join(this.weapp, basicPath, otherPath.length === 0 ? '' : path.join(otherPath))
const urlObj = {
protocol: 'http:',
slashes: true,
hostname: this.host,
port: this.port,
search: '?' + urlQuery,
pathname: urlPath
}
return url.format(urlObj);
}

getVersion () {
const url = this.formatUrl([this.versionUri])
return sendGetRequest(url)
}
}
31 changes: 31 additions & 0 deletions src/utils/sendRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Created by Chyroc on 17/1/10.
*/

const fetch = require('isomorphic-fetch')

function sendRequest (method, url, body = null) {
return fetch(url, {method: method, body: body})
.then(function (res) {
return res.json()
})
.catch(function (err) {
console.log(err)
})
}

export function sendGetRequest (url, body = null) {
return sendRequest('GET', url, body)
}

export function senPostRequest (url, body) {
return sendRequest('POST', url, body)
}

export function senPutRequest (url, body) {
return sendRequest('PUT', url, body)
}

export function senDeleteRequest (url, body = null) {
return sendRequest('DELETE', url, body)
}
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Created by Chyroc on 17/1/10.
*/

import { Hasoop } from '../src/index'

const config = {
'userName': 'Developer',
'host': 'localhost',
'port': 12000,
'webapp': 'sqoop'
}
export const sqoopClient = new Hasoop(config)
11 changes: 5 additions & 6 deletions test/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
*/

import { expect } from 'chai'
import { Hasoop } from '../src/index'

const sqoopClient = new Hasoop('')
import { sqoopClient } from './index'

suite('utils', () => {
test.skip('getVersion', () => {
sqoopClient.getVersion()
test('getVersion', async () => {
const data = await sqoopClient.getVersion()
expect(data).to.be.an('object')
expect(data['api-versions'][0]).to.equal('v1')
})

})
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@ babel-plugin-transform-regenerator@^6.16.0:
dependencies:
regenerator-transform "0.9.8"

babel-plugin-transform-runtime@^6.15.0:
version "6.15.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.15.0.tgz#3d75b4d949ad81af157570273846fb59aeb0d57c"
dependencies:
babel-runtime "^6.9.0"

babel-plugin-transform-strict-mode@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.18.0.tgz#df7cf2991fe046f44163dcd110d5ca43bc652b9d"
Expand Down