1import ./make-test-python.nix ({ pkgs, ...} :
2let
3 accessKey = "BKIKJAA5BMMU2RHO6IBB";
4 secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
5 minioPythonScript = pkgs.writeScript "minio-test.py" ''
6 #! ${pkgs.python3.withPackages(ps: [ ps.minio ])}/bin/python
7 import io
8 import os
9 from minio import Minio
10 minioClient = Minio('localhost:9000',
11 access_key='${accessKey}',
12 secret_key='${secretKey}',
13 secure=False)
14 sio = io.BytesIO()
15 sio.write(b'Test from Python')
16 sio.seek(0, os.SEEK_END)
17 sio_len = sio.tell()
18 sio.seek(0)
19 minioClient.put_object('test-bucket', 'test.txt', sio, sio_len, content_type='text/plain')
20 '';
21in {
22 name = "minio";
23 meta = with pkgs.lib.maintainers; {
24 maintainers = [ bachp ];
25 };
26
27 nodes = {
28 machine = { pkgs, ... }: {
29 services.minio = {
30 enable = true;
31 inherit accessKey secretKey;
32 };
33 environment.systemPackages = [ pkgs.minio-client ];
34
35 # Minio requires at least 1GiB of free disk space to run.
36 virtualisation.diskSize = 4 * 1024;
37 };
38 };
39
40 testScript = ''
41 start_all()
42 machine.wait_for_unit("minio.service")
43 machine.wait_for_open_port(9000)
44
45 # Create a test bucket on the server
46 machine.succeed(
47 "mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4"
48 )
49 machine.succeed("mc mb minio/test-bucket")
50 machine.succeed("${minioPythonScript}")
51 assert "test-bucket" in machine.succeed("mc ls minio")
52 assert "Test from Python" in machine.succeed("mc cat minio/test-bucket/test.txt")
53 machine.shutdown()
54 '';
55})