Пример #1
0
  it("organizes nodes by locality", function() {
    const state = makeStateWithLocalities([
      [{ key: "region", value: "us-east-1" }],
      [{ key: "region", value: "us-east-2" }],
    ]);

    const tree = selectLocalityTree(state);

    assert.isEmpty(tree.tiers);
    assert.isEmpty(tree.nodes);

    assert.hasAllKeys(tree.localities, ["region"] );
    const regions = tree.localities.region;

    assert.hasAllKeys(regions, ["us-east-1", "us-east-2"]);

    const usEast1 = regions["us-east-1"];

    assert.isEmpty(usEast1.localities);
    assert.deepEqual(usEast1.tiers, [{ key: "region", value: "us-east-1" }]);

    assert.lengthOf(usEast1.nodes, 1);

    const usEast2 = regions["us-east-2"];

    assert.isEmpty(usEast2.localities);
    assert.deepEqual(usEast2.tiers, [{ key: "region", value: "us-east-2" }]);

    assert.lengthOf(usEast2.nodes, 1);
  });
Пример #2
0
        it('should add mix route names as sub-routes', () => {
            let parentRoute = new Route();

            parentRoute.get('/a', () => {});
            parentRoute.get('/b', () => {});

            let subRoute = new Route();
            subRoute.get('/aa', () => {});
            subRoute.get('/ab', () => {});

            parentRoute.add('/a', subRoute);
            parentRoute.add('b/', subRoute);
            parentRoute.add(' c', subRoute);

            assert.hasAllKeys(parentRoute.nextRoute, ['a', 'b', 'c'], 'Sub route not added');
            assert.hasAnyKeys(
                parentRoute.nextRoute['a'].nextRoute,
                ['aa', 'ab'],
                'Sub-sub route `a` not added'
            );
            assert.hasAnyKeys(
                parentRoute.nextRoute['b'].nextRoute,
                ['aa', 'ab'],
                'Sub-sub route `b` not added'
            );
            assert.hasAnyKeys(
                parentRoute.nextRoute['c'].nextRoute,
                ['aa', 'ab'],
                'Sub-sub route `c` not added'
            );
        });
Пример #3
0
  it("makes a key for each locality value in each tier", function() {
    const cities = [
      "nyc",
      "sf",
      "walla-walla",
    ];
    const dataCenters = [
      "us-east-1",
      "us-west-1",
    ];
    const cityLocations = cities.map((city) => ({ locality_key: "city", locality_value: city }));
    const dcLocations = dataCenters.map((dc) => ({ locality_key: "data-center", locality_value: dc }));
    const state = makeStateWithLocations(cityLocations.concat(dcLocations));

    const tree = selectLocationTree(state);

    assert.hasAllKeys(tree, ["city", "data-center"]);
    assert.hasAllKeys(tree.city, cities);
    assert.hasAllKeys(tree["data-center"], dataCenters);
  });
Пример #4
0
  it("makes a key for each locality tier in locations", function() {
    const tiers = [
      "region",
      "city",
      "data-center",
      "rack",
    ];
    const locations = tiers.map((tier) => ({ locality_key: tier }));
    const state = makeStateWithLocations(locations);

    assert.hasAllKeys(selectLocationTree(state), tiers);
  });
Пример #5
0
    test(fixture, async () => {
      let config: Config = {};
      const configPath = path.join(fixtures, fixture, 'gen-tsd.json');
      if (fs.existsSync(configPath)) {
        config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
      }
      config.hideWarnings = true;

      const actual =
          await generateDeclarations(path.join(fixtures, fixture), config);
      const golden = readDirAsMap(path.join(goldens, fixture));
      assert.hasAllKeys(actual, [...golden.keys()]);
      for (const filename of actual.keys()) {
        assert.equal(actual.get(filename), golden.get(filename), filename);
      }
    }).timeout(30000);  // These tests can take a long time.
Пример #6
0
        it('should add get route', () => {
            assert.isUndefined(helloRoute.getFunction);
            helloRoute.get(randomRoute, simpleRouteFunction);
            helloRoute.get(newRoute, simpleRouteFunction);
            assert.isUndefined(helloRoute.getFunction);

            helloRoute.get('/', simpleRouteFunction);

            assert.hasAllKeys(
                helloRoute.nextRoute,
                ['random', 'newRoute'],
                'Random route not added'
            );
            assert.isFunction(helloRoute.getFunction);

            assert.isFunction(helloRoute.nextRoute.random.getFunction);
            assert.isFunction(helloRoute.nextRoute.newRoute.getFunction);
        });
Пример #7
0
        it('should add multilevel sub-routes', () => {
            let parentRoute = new Route();

            parentRoute.get('/a', () => {});
            parentRoute.get('/b', () => {});

            let subRoute = new Route();
            subRoute.get('/aa', () => {});
            subRoute.get('/ab', () => {});

            parentRoute.add('/a/b', subRoute);
            parentRoute.add('/c/a', subRoute);
            parentRoute.add('/c/b/a', subRoute);

            assert.hasAllKeys(parentRoute.nextRoute, ['a', 'b', 'c'], 'Sub route not added');
            assert.hasAllKeys(
                parentRoute.nextRoute['a'].nextRoute,
                ['b'],
                'Sub-sub route `a` not added'
            );
            assert.hasAllKeys(
                parentRoute.nextRoute['a'].nextRoute['b'].nextRoute,
                ['aa', 'ab'],
                'Sub-sub route `aa` `ab` not added'
            );
            assert.hasAllKeys(
                parentRoute.nextRoute['c'].nextRoute,
                ['a', 'b'],
                'Sub-sub route `a` not added to route `c`'
            );
            assert.hasAllKeys(
                parentRoute.nextRoute['c'].nextRoute['a'].nextRoute,
                ['aa', 'ab'],
                'Sub-sub route `a` not added to route `c`'
            );
            assert.hasAllKeys(
                parentRoute.nextRoute['c'].nextRoute['b'].nextRoute,
                ['a'],
                'Sub-sub route `a` not added to route `c`'
            );
            assert.hasAllKeys(
                parentRoute.nextRoute['c'].nextRoute['b'].nextRoute['a'].nextRoute,
                ['aa', 'ab'],
                'Sub-sub route `a` not added to route `c`'
            );
        });