CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/jupyter/test/blobs.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import expect from "expect";
7
8
import * as misc_node from "@cocalc/backend/misc_node";
9
10
import { blob_store } from "@cocalc/jupyter/blobs";
11
12
describe("very basic tests of the blob store -- ", function () {
13
const blob_store = get_blob_store();
14
if (blob_store == null) {
15
throw Error("blob_store is null");
16
}
17
18
blob_store.delete_all_blobs();
19
20
it("gets a list of blobs (which should be empty)", () => {
21
expect(blob_store.keys()).toEqual([]);
22
});
23
24
// got via
25
// require('./jupyter').kernel(name:'sage-7.4', verbose:false).execute_code(code:'point((0,0), axes=False, figsize=1)', all:true, cb:(e,m)->console.log(m[2].content.data))
26
const blob =
27
"iVBORw0KGgoAAAANSUhEUgAAAFkAAAA4CAYAAACWo1RQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAAQVJREFUeJzt2iEOwjAcRvEPwuSSSY4AbmbciFNxil0DhYNj4CeGmAAc\nCF7T8H7JkrXqn5emqqt5nufop9alB/gHRgYYGWBkgJEBRgYYGWBkgJEBRgYYGWBkgJEBRgYYGWBk\ngJEBRgYYGWBkgJEBRgYYGWBkwKb0AN+435PTafk/HpOuKzvPp1a1vCCapuRwSC6XZd33yfmcNE3Z\nuT5RTeTbLdnv3/eu12S3KzPPN6q5k7fbpG2f67Zd9mpQTeSuS8YxGYblG0fvZL2o5iTXzMgAIwOM\nDDAywMgAIwOMDDAywMgAIwOMDDAywMgAIwOMDDAywMgAIwOMDDAywMgAIwOMDDAy4AEJciLL9Myg\nZwAAAABJRU5ErkJggg==\n";
28
const buffer = Buffer.from(blob, "base64");
29
const sha1 = misc_node.sha1(buffer);
30
31
it("saves a blob", () => {
32
expect(blob_store.save(blob, "image/png")).toBe(sha1);
33
expect(blob_store.keys()).toEqual([sha1]);
34
});
35
36
it("reads a blob", () => {
37
expect(blob_store.get(sha1)).toEqual(buffer);
38
});
39
});
40
41