mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
fix tests
This commit is contained in:
parent
fd7fbc0f3c
commit
db223f1dc6
@ -2,8 +2,8 @@ var config = {
|
|||||||
min_size: 1, // < 1 will (obviously) cause crash
|
min_size: 1, // < 1 will (obviously) cause crash
|
||||||
max_size: 512, // too big values might lead to slow response time or DoS
|
max_size: 512, // too big values might lead to slow response time or DoS
|
||||||
default_size: 160, // size to be used when no size given
|
default_size: 160, // size to be used when no size given
|
||||||
local_cache_time: 3600, // seconds until we will check if the image changed. should be > 60 to prevent mojang 429 response
|
local_cache_time: 30, // seconds until we will check if the image changed. should be > 60 to prevent mojang 429 response
|
||||||
browser_cache_time: 3600, // seconds until browser will request image again
|
browser_cache_time: 30, // seconds until browser will request image again
|
||||||
http_timeout: 3000, // ms until connection to mojang is dropped
|
http_timeout: 3000, // ms until connection to mojang is dropped
|
||||||
faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
|
faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
|
||||||
helms_dir: 'skins/helms/', // directory where helms are kept. should have trailing '/'
|
helms_dir: 'skins/helms/', // directory where helms are kept. should have trailing '/'
|
||||||
|
|||||||
@ -35,11 +35,12 @@ function store_images(uuid, details, callback) {
|
|||||||
logging.log(uuid + " new hash: " + hash);
|
logging.log(uuid + " new hash: " + hash);
|
||||||
var facepath = __dirname + '/../' + config.faces_dir + hash + ".png";
|
var facepath = __dirname + '/../' + config.faces_dir + hash + ".png";
|
||||||
var helmpath = __dirname + '/../' + config.helms_dir + hash + ".png";
|
var helmpath = __dirname + '/../' + config.helms_dir + hash + ".png";
|
||||||
// download skin, extract face/helm
|
// download skin
|
||||||
networking.skin_file(skin_url, facepath, function(err, img) {
|
networking.get_skin(skin_url, function(err, img) {
|
||||||
if (err) {
|
if (err || !img) {
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
} else {
|
} else {
|
||||||
|
// extract face / helm
|
||||||
skins.extract_face(img, facepath, function(err) {
|
skins.extract_face(img, facepath, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
@ -148,7 +149,7 @@ exp.get_skin = function(uuid, callback) {
|
|||||||
exp.get_image_hash(uuid, function(err, status, hash) {
|
exp.get_image_hash(uuid, function(err, status, hash) {
|
||||||
if (hash) {
|
if (hash) {
|
||||||
var skinurl = "http://textures.minecraft.net/texture/" + hash;
|
var skinurl = "http://textures.minecraft.net/texture/" + hash;
|
||||||
networking.skin_file(skinurl, null, function(err, img) {
|
networking.get_skin(skinurl, null, function(err, img) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logging.log("\nerror while downloading skin");
|
logging.log("\nerror while downloading skin");
|
||||||
callback(err, hash, null);
|
callback(err, hash, null);
|
||||||
|
|||||||
@ -99,15 +99,8 @@ exp.get_skin_url = function(uuid, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// downloads skin file from +url+
|
// downloads skin file from +url+
|
||||||
// stores face image as +facename+
|
// callback contains error, image
|
||||||
// stores helm image as +helmname+
|
exp.get_skin = function(url, callback) {
|
||||||
// callback contains error
|
|
||||||
exp.skin_file = function(url, facename, callback) {
|
|
||||||
if (facename && fs.existsSync(facename)) {
|
|
||||||
logging.log("Images already exist, not downloading.");
|
|
||||||
callback(null, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
request.get({
|
request.get({
|
||||||
url: url,
|
url: url,
|
||||||
encoding: null, // encoding must be null so we get a buffer
|
encoding: null, // encoding must be null so we get a buffer
|
||||||
|
|||||||
23
test/test.js
23
test/test.js
@ -23,6 +23,9 @@ var username = usernames[Math.round(Math.random() * (usernames.length - 1))];
|
|||||||
console.log("using username '" + username + "'");
|
console.log("using username '" + username + "'");
|
||||||
|
|
||||||
describe('Crafatar', function() {
|
describe('Crafatar', function() {
|
||||||
|
// we might have to make 2 HTTP requests
|
||||||
|
this.timeout(config.http_timeout * 2 + 50);
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
cache.get_redis().flushall();
|
cache.get_redis().flushall();
|
||||||
});
|
});
|
||||||
@ -131,10 +134,15 @@ describe('Crafatar', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should already have the files / not download", function(done) {
|
it("should already have the files / not download", function(done) {
|
||||||
|
|
||||||
|
// FIXME: implement & remove this line
|
||||||
|
throw("Please re-implement this and add a new test");
|
||||||
|
|
||||||
|
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
fs.openSync("face.png", "w");
|
fs.openSync("face.png", "w");
|
||||||
fs.openSync("helm.png", "w");
|
fs.openSync("helm.png", "w");
|
||||||
networking.skin_file("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", "face.png", function(err) {
|
networking.get_skin("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(err, img) {
|
||||||
assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
|
assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
|
||||||
fs.unlinkSync("face.png");
|
fs.unlinkSync("face.png");
|
||||||
fs.unlinkSync("helm.png");
|
fs.unlinkSync("helm.png");
|
||||||
@ -189,7 +197,7 @@ describe('Crafatar', function() {
|
|||||||
it("should time out on skin download", function(done) {
|
it("should time out on skin download", function(done) {
|
||||||
var original_timeout = config.http_timeout;
|
var original_timeout = config.http_timeout;
|
||||||
config.http_timeout = 1;
|
config.http_timeout = 1;
|
||||||
networking.skin_file("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", "face.png", function(err) {
|
networking.get_skin("http://textures.minecraft.net/texture/477be35554684c28bdeee4cf11c591d3c88afb77e0b98da893fd7bc318c65184", function(err, img) {
|
||||||
assert.strictEqual(err.code, "ETIMEDOUT");
|
assert.strictEqual(err.code, "ETIMEDOUT");
|
||||||
config.http_timeout = original_timeout;
|
config.http_timeout = original_timeout;
|
||||||
done();
|
done();
|
||||||
@ -197,7 +205,7 @@ describe('Crafatar', function() {
|
|||||||
});
|
});
|
||||||
it("should not find the skin", function(done) {
|
it("should not find the skin", function(done) {
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
networking.skin_file("http://textures.minecraft.net/texture/this-does-not-exist", "face.png", function(err) {
|
networking.get_skin("http://textures.minecraft.net/texture/this-does-not-exist", function(err, img) {
|
||||||
assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
|
assert.strictEqual(err, null); // no error here, but it shouldn't throw exceptions
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -210,4 +218,13 @@ describe('Crafatar', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
try {
|
||||||
|
// these files could be here if a test failed
|
||||||
|
fs.unlinkSync("face.png");
|
||||||
|
fs.unlinkSync("helm.png");
|
||||||
|
} catch(e){}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user