{"id":18467164,"url":"https://github.com/draganm/miniotest","last_synced_at":"2025-07-15T03:33:33.243Z","repository":{"id":57560166,"uuid":"325390650","full_name":"draganm/miniotest","owner":"draganm","description":"Golang module for embedded integration testing of AWS S3 client interactions","archived":false,"fork":false,"pushed_at":"2021-01-02T22:19:43.000Z","size":43,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T09:43:26.997Z","etag":null,"topics":["golang","integration-tests","minio","s3"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/draganm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-29T21:28:48.000Z","updated_at":"2024-09-12T08:32:53.000Z","dependencies_parsed_at":"2022-08-26T07:01:35.507Z","dependency_job_id":null,"html_url":"https://github.com/draganm/miniotest","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/draganm/miniotest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draganm%2Fminiotest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draganm%2Fminiotest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draganm%2Fminiotest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draganm%2Fminiotest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/draganm","download_url":"https://codeload.github.com/draganm/miniotest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draganm%2Fminiotest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265397641,"owners_count":23758450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","integration-tests","minio","s3"],"created_at":"2024-11-06T09:19:05.519Z","updated_at":"2025-07-15T03:33:33.197Z","avatar_url":"https://github.com/draganm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Miniotest\n\nConvenience Golang module enabling you to run embedded [Minio](https://min.io/) server for purpose of integration testing of AWS S3 operations.\n\n## Motivation\n\nThere is an [open feature request](https://github.com/minio/minio/issues/5146) on the [Minio GitHub project](https://github.com/minio/minio).\nIt describes the necessary steps to use Minio in your tests, but still there is no easily (re-)useable code for that purpose.\n\nNotably, following features would we very useful:\n- Do no hard-code the port to which Minio server will bind, instead use a free port determined at run time\n- Create a bucket after starting the server\n- Provide a tear-down function that will shut down the Minio server after the test is done\n- Clean up files created by the test after the test is done\n\nAll of those features are provided by this module.\n\n## Requirements\n\n- Golang 1.15: uses Golang's test [TempDir](https://golang.org/pkg/testing/#T.TempDir) feature\n\n## Installation\n\n```bash\n$ go get github.com/draganm/miniotest\n\n```\n\n## Use\n[this project's test](./miniotest_test.go) demonstrates the use of the embedded Minio for testing.\n\n**UPDATE** it turns out that starting/stopping/starting Minio sever in this way does not work.\nThis is because there are quite a few global states and signal handlers being installed and not cleaned up.\n\nBecause of this, one can start the embedded server only once per test process and use [test Main()](https://golang.org/pkg/testing/#hdr-Main)\nmethod to set up / tear down the embedded server.\n\nOn the up side, one can create one bucket per test, so there won't be any interferences between tests, unless one tests creation of buckets.\n\n\n```golang\nfunc Test1(t *testing.T) {\n\n\tmc, err := mclient.New(addr, \u0026mclient.Options{\n\t\tCreds:  credentials.NewStaticV4(\"minioadmin\", \"minioadmin\", \"\"),\n\t\tSecure: false,\n\t})\n\trequire.NoError(t, err)\n\n\tdata := []byte(\"test\")\n\n\t_, err = mc.PutObject(context.Background(), \"test\", \"foo/var\", bytes.NewReader(data), int64(len(data)), mclient.PutObjectOptions{})\n\trequire.NoError(t, err)\n}\n\nfunc Test2(t *testing.T) {\n\n\tmc, err := mclient.New(addr, \u0026mclient.Options{\n\t\tCreds:  credentials.NewStaticV4(\"minioadmin\", \"minioadmin\", \"\"),\n\t\tSecure: false,\n\t})\n\trequire.NoError(t, err)\n\n\tdata := []byte(\"test\")\n\n\t_, err = mc.PutObject(context.Background(), \"test\", \"foo/var\", bytes.NewReader(data), int64(len(data)), mclient.PutObjectOptions{})\n\trequire.NoError(t, err)\n}\n\nvar addr string\n\nfunc TestMain(m *testing.M) {\n\tvar cleanup func() error\n\tvar err error\n\taddr, cleanup, err = miniotest.StartEmbedded()\n\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"while starting embedded server: %s\", err)\n\t\tos.Exit(1)\n\t}\n\n\texitCode := m.Run()\n\n\terr = cleanup()\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"while stopping embedded server: %s\", err)\n\t}\n\n\tos.Exit(exitCode)\n}\n```\n\nFunction `miniotest.StartEmbedded()` starts Minio server and returns a string representing bound `address:port` where Minio is listening.\nYou can use this address as the endpoint for your S3 client (e.g. minio client).\n\nSecond value returned is a function that will shut down the started Minio server when called.\nThe best use of this function is to be deferred until the test function returns (as shown in the example).\n\n## Default values\n\n### Hostname and port\n\nMiniotest will force embedded Minio server to bind to `localhost` and a free port.\nFree port is determined by opening a TCP listener with the port `0`, getting the bound port and closing the listener.\n`hostname:port` bind address will be returned as the first return value of `miniotest.StartEmbedded()`\n\nNote: there is a possible race condition with this approach, which can lead to Minio server not starting if some other process binds the same port between closing the listener and starting the Minio server.\nWindow of opportunity for this to happen is very short and one can assume this won't happen in 99.999% of cases.\n\n### `accessKeyID` and `secretAccessKey`\n\nWhen not specified otherwise, Minio will assume that both `accessKeyID` and `secretAccessKey` are set to `minioadmin` and you should be using this for your tests.\nPlease do not set environment variables `MINIO_ACCESS_KEY` and `MINIO_SECRET_KEY` because this will break the setup code for the embedded Minio server.\n\n\n### Automatically created bucket\n\nMiniotest will create bucket named `test` as a convenience for the tests run.\n\n### Secure mode\n\nEmbedded Minio server won't be listening for TLS connections, hence one should not use the S3 client with this option enabled.\nIf someone really needs this feature, please raise an issue on this project, or even better offer a pull request for it.\n\n## Contributing\n\nContributions are welcome, send your issues and PRs to this repo.\n\n## License\n\n[MIT](LICENSE) - Copyright Dragan Milic and contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdraganm%2Fminiotest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdraganm%2Fminiotest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdraganm%2Fminiotest/lists"}