summaryrefslogtreecommitdiffstats
path: root/nixos/tests/rustfs.nix
blob: 7cace30e3bfceeb6f2a1843608384023677f400d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{ pkgs, ... }:

let
  accessKey = "BKIKJAA5BMMU2RHO6IBB";
  secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";

  rustfsPythonScript =
    pkgs.writers.writePython3 "rustfs-test" { libraries = with pkgs.python3Packages; [ minio ]; }
      /* python */ ''
        import io
        import os
        from minio import Minio

        minioClient = Minio(
          'localhost:9000',
          access_key='${accessKey}',
          secret_key='${secretKey}',
          secure=False
        )
        sio = io.BytesIO()
        sio.write(b'Test from Python')
        sio.seek(0, os.SEEK_END)
        sio_len = sio.tell()
        sio.seek(0)
        minioClient.put_object(
          'test-bucket',
          'test.txt',
          sio,
          sio_len,
          content_type='text/plain'
        )
      '';

in
{
  name = "rustfs";
  meta = with pkgs.lib.maintainers; {
    maintainers = [
      marcel
    ];
  };

  containers.machine =
    { pkgs, ... }:
    {
      services.rustfs = {
        enable = true;
        environmentFile = builtins.toString (
          pkgs.writeText "rustfs-secrets.env" ''
            RUSTFS_ACCESS_KEY=${accessKey}
            RUSTFS_SECRET_KEY=${secretKey}
          ''
        );
      };

      environment.systemPackages = with pkgs; [ minio-client ];
    };

  testScript = /* python */ ''
    machine.wait_for_unit("rustfs.service")

    machine.succeed("mc alias set rustfs http://localhost:9000 ${accessKey} ${secretKey} --api s3v4")
    machine.succeed("mc mb rustfs/test-bucket")
    machine.succeed("${rustfsPythonScript}")
    assert "test-bucket" in machine.succeed("mc ls rustfs")
    assert "Test from Python" in machine.succeed("mc cat rustfs/test-bucket/test.txt")
    machine.succeed("mc rb --force rustfs/test-bucket")
  '';
}