記事
· 11 hr 前 5m read

testcontainers-iris-nodeの紹介。Node.jsでIRIS統合テストを簡素化する

概要統合とE2Eテストのために一時的なInterSystems IRISコンテナの起動を簡単にするNode.jsライブラリ、testcontainers-iris-nodeのリリースをお知らせします。 このプロジェクトが、testcontainers-iris-pythontestcontainers-iris-javaなどを含む、IRIS用Testcontainersアダプターの既存ファミリーに加わるのは極めて自然なことです。

testcontainers-iris-nodeを使う理由とは?InterSystems IRISで作業するNode.js開発者として、本番環境を再現するテスト環境を設定する際によく問題にぶつかりました。 testcontainers-iris-nodeは、オンデマンドで隔離されたIRIS環境を作成するためにtestcontainers-nodeフレームワークを活用することで、この問題を解決しました。

これは次において特に有用です。

  • IRISデータベースとの統合テスト
  • データパイプラインやマイクロサービスのテスト
  • CIパイプラインでのテスト環境の自動化

機能

  • Testcontainersを使用してDockerコンテナでIRISを起動します
  • カスタムのDockerイメージと構成をサポートします
  • テスト開始前にIRISが準備完了していることを確認するための待機戦略
  • テスト実行間のクリーンなティアダウン

はじめに

npm install testcontainers-iris --save-dev

使用例

import { IRISContainer } from "testcontainers-iris";
import { createConnection } from "@intersystems/intersystems-iris-native";

const IMAGE = "containers.intersystems.com/intersystems/iris-community:latest-preview";
const container = await new IRISContainer(IMAGE).start();
const connection = createConnection(container.getConnectionOptions());
const iris = connection.createIris();
const version = iris.classMethodString("%SYSTEM.Version", "GetNumber");

仕組み:内部では、このライブラリはtestcontainersGenericContainerを拡張し、IRIS固有の待機戦略を追加するとともに、接続文字列の生成や設定の上書きのためのヘルパーメソッドを提供しています。

サポートされているシナリオ

  • JestまたはMochaベースのテストスイート
  • CI環境(GitHub Actions、GitLab CI、Jenkinsなど)
  • ローカル開発とデバッグ

Mochaのテスト例:Mochaを使った堅牢な統合テストにもこのライブラリを利用できます。 こちらは設定の例です。

test-setup.ts

import "source-map-support/register"
import "reflect-metadata"
import { IRISContainer, StartedIRISContainer } from "testcontainers-iris"
import { IRISNative } from "../../src"
import chai from "chai"
import sinonChai from "sinon-chai"
import chaiAsPromised from "chai-as-promised"
declare global {
    var container: StartedIRISContainer | undefined
    var connectionOptions: {
        host: string
        port: number
        user: string
        pwd: string
        ns: string
    }
}

process.env.TZ = "UTC"
chai.should()
chai.use(sinonChai)
chai.use(chaiAsPromised)

before(async () => {
    console.log("Setting up test environment...")
    const image = process.env["IRIS_IMAGE"]
    let connectionOptions = {
        host: "localhost",
        port: 1972,
        user: "_SYSTEM",
        pwd: "SYS",
        ns: "USER",
    }
    if (image) {
        const container: StartedIRISContainer = await new IRISContainer(image)
            .withNamespace("TEST")
            .start()
        console.log(`IRIS container started at ${container.getConnectionUri()}`)
        global.container = container
        connectionOptions = {
            host: container.getHost(),
            port: container.getMappedPort(1972),
            user: container.getUsername(),
            pwd: container.getPassword(),
            ns: container.getNamespace(),
        }
    }
    global.connectionOptions = connectionOptions
    IRISNative.createConnection({ ...connectionOptions, sharedmemory: false })
})

after(async () => {
    console.log("Cleaning up test environment...")
    if (global.container) {
        await global.container.stop()
    }
    delete global.container
})

テストケース:

import { IRISNative, IRISConnection } from "../src/IRISNative"
describe("IRISNative test", () => {
    let connection: IRISConnection
    before(() => {
        const connectionOptions = global.connectionOptions
        connection = IRISNative.createConnection({ ...connectionOptions })
    })
    after(() => {
        if (connection) {
            connection.close()
        }
    })
    it("should work", async () => {
        const res = await connection.query(
            "SELECT 1 AS test1, '2' AS test2",
            [],
        )
        res.rows.should.be.an("array")
        res.rows.should.have.lengthOf(1)
        res.rows[0].should.be.an("object")
        res.rows[0].should.have.property("test1")
        res.rows[0].should.have.property("test2")
        res.rows[0].should.have.property("test1", 1)
        res.rows[0].should.have.property("test2", "2")
    })
})

typeorm-irisで使用:このライブラリはtypeorm-irisプロジェクトでも使用されています。これはInterSystems IRISでの実験的なTypeORMサポートを提供します。 testcontainers-iris-nodeにより、そのプロジェクトの統合テスト設定が強化され、実際のIRISインスタンスを使ってORMの機能を検証するのに役立ちます。

ライブラリ採用の課題:ライブラリ採用開発者として、最大の課題の一つは複数バージョンのInterSystems IRISでのテストです。 このツールは、異なるIRISバージョンを使用したコンテナ環境の切り替えと自動化を容易にすることで、そのプロセスを大幅に簡素化します。

他の言語のバインディングとの比較testcontainers-iris-pythontestcontainers-iris-javaは成熟しており、バインドマウントやカスタム起動スクリプトなどの高度な機能をサポートしています。一方で、Node.js版は JavaScript/TypeScript環境向けにシンプルさと開発者の使いやすさを重視して設計されています。

貢献とフィードバックフィードバック、Issue、プルリクエストはGitHubのtestcontainers-iris-nodeにてお待ちしています。

まとめtestcontainers-iris-nodeは、Node.jsエコシステムにおいて、IRISベースのアプリケーションに対する堅牢かつ自動化されたテストのハードルを下げます。 API、ETLジョブ、または統合サービスなど、どの構築でも、このツールはIRISワークフローに対する信頼性を向上させます。

ディスカッション (0)0
続けるにはログインするか新規登録を行ってください