testcontainers-redis 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +149 -0
- data/Rakefile +14 -0
- data/lib/testcontainers/redis/version.rb +7 -0
- data/lib/testcontainers/redis.rb +70 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ca35e10e3cf74f54fde8d1701bb3d275176bc511e4759d9065daf0d5885a27bd
|
4
|
+
data.tar.gz: 47bc00397d4d39c5824bba2691bef242e68c52e7525a695627da5e408ade997e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c196752899a7430b2b0ed79e955248c5f220961de30d40046e4d7f7973a29eebf6a9d474154c3a98114f389432a97595b81239aad0c7e7fb86b3bc5d0ffe4dd
|
7
|
+
data.tar.gz: 0afd3c2cf257ad42f6d725cea831050987c10f647a9800d99d6172f8237740de1cc2b47650155e37d251976ad941ce9534605dd3cc21b263cea9505a2c2e21f5
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../core
|
3
|
+
specs:
|
4
|
+
testcontainers-core (0.1.1)
|
5
|
+
docker-api (~> 2.2)
|
6
|
+
|
7
|
+
PATH
|
8
|
+
remote: .
|
9
|
+
specs:
|
10
|
+
testcontainers-redis (0.1.0)
|
11
|
+
testcontainers-core (~> 0.1.1)
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
ast (2.4.2)
|
17
|
+
connection_pool (2.4.0)
|
18
|
+
docker-api (2.2.0)
|
19
|
+
excon (>= 0.47.0)
|
20
|
+
multi_json
|
21
|
+
excon (0.99.0)
|
22
|
+
json (2.6.3)
|
23
|
+
language_server-protocol (3.17.0.3)
|
24
|
+
lint_roller (1.0.0)
|
25
|
+
minitest (5.18.0)
|
26
|
+
minitest-hooks (1.5.0)
|
27
|
+
minitest (> 5.3)
|
28
|
+
multi_json (1.15.0)
|
29
|
+
parallel (1.23.0)
|
30
|
+
parser (3.2.2.1)
|
31
|
+
ast (~> 2.4.1)
|
32
|
+
rainbow (3.1.1)
|
33
|
+
rake (13.0.6)
|
34
|
+
redis (5.0.6)
|
35
|
+
redis-client (>= 0.9.0)
|
36
|
+
redis-client (0.14.1)
|
37
|
+
connection_pool
|
38
|
+
regexp_parser (2.8.0)
|
39
|
+
rexml (3.2.5)
|
40
|
+
rubocop (1.50.2)
|
41
|
+
json (~> 2.3)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 3.2.0.0)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 1.8, < 3.0)
|
46
|
+
rexml (>= 3.2.5, < 4.0)
|
47
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
50
|
+
rubocop-ast (1.28.1)
|
51
|
+
parser (>= 3.2.1.0)
|
52
|
+
rubocop-performance (1.16.0)
|
53
|
+
rubocop (>= 1.7.0, < 2.0)
|
54
|
+
rubocop-ast (>= 0.4.0)
|
55
|
+
ruby-progressbar (1.13.0)
|
56
|
+
standard (1.28.2)
|
57
|
+
language_server-protocol (~> 3.17.0.2)
|
58
|
+
lint_roller (~> 1.0)
|
59
|
+
rubocop (~> 1.50.2)
|
60
|
+
standard-custom (~> 1.0.0)
|
61
|
+
standard-performance (~> 1.0.1)
|
62
|
+
standard-custom (1.0.0)
|
63
|
+
lint_roller (~> 1.0)
|
64
|
+
standard-performance (1.0.1)
|
65
|
+
lint_roller (~> 1.0)
|
66
|
+
rubocop-performance (~> 1.16.0)
|
67
|
+
unicode-display_width (2.4.2)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
arm64-darwin-21
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
minitest (~> 5.0)
|
74
|
+
minitest-hooks (~> 1.5)
|
75
|
+
rake (~> 13.0)
|
76
|
+
redis (~> 5.0)
|
77
|
+
standard (~> 1.3)
|
78
|
+
testcontainers-core!
|
79
|
+
testcontainers-redis!
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
2.4.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Guillermo Iguaran
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# Testcontainers module for Redis
|
2
|
+
|
3
|
+
`testcontainers-redis` simplifies the creation and management of Redis containers for testing purposes using the Testcontainers library.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the library to the test section in your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :test do
|
11
|
+
gem 'testcontainers-redis'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
$ gem install testcontainers-redis
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
To use the library, you first need to require it:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'testcontainers/redis'
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
### Creating a Redis container
|
42
|
+
|
43
|
+
Create a new instance of the `Testcontainers::RedisContainer` class:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
container = Testcontainers::RedisContainer.new
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
This creates a new container with the default Redis image. You can customize these by passing arguments to the constructor:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
container = Testcontainers::RedisContainer.new("redis:6.0-alpine", password: "custom_pass")
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
### Starting and stopping the container
|
59
|
+
|
60
|
+
Start the container:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
container.start
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
Stop the container when you're done:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
container.stop
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
### Connecting to the Redis container
|
76
|
+
|
77
|
+
Once the container is running, you can obtain the connection details using the following methods:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
host = container.host
|
81
|
+
port = container.first_mapped_port
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
Or, you can generate a full Redis URL:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
redis_url = container.redis_url
|
90
|
+
```
|
91
|
+
|
92
|
+
Use this URL to connect to the Redis container using your preferred Redis client library.
|
93
|
+
|
94
|
+
### Customizing the container
|
95
|
+
|
96
|
+
You can also customize the container before of starting it, e.g setting a custom password for
|
97
|
+
client's authentication:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
container.with_password("custom_pass")
|
101
|
+
```
|
102
|
+
|
103
|
+
or using a custom `redis.conf` (saved under `$PWD/custom/conf` in this
|
104
|
+
example):
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
container.with_filesystem_binds(["#{Dir.pwd}/custom/conf:/usr/local/etc/redis:rw"])
|
108
|
+
container.with_cmd("redis-server /usr/local/etc/redis/redis.conf")
|
109
|
+
```
|
110
|
+
|
111
|
+
### Example
|
112
|
+
|
113
|
+
Here's a complete example of how to use `testcontainers-redis` to create a container, connect to it, and run a simple command:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
require 'testcontainers/redis'
|
117
|
+
require 'redis'
|
118
|
+
|
119
|
+
container = Testcontainers::RedisContainer.new
|
120
|
+
container.start
|
121
|
+
|
122
|
+
client = Redis.new(url: container.redis_url)
|
123
|
+
|
124
|
+
client.set("mykey", "hello world")
|
125
|
+
value = client.get("mykey")
|
126
|
+
|
127
|
+
puts value
|
128
|
+
|
129
|
+
client.quit
|
130
|
+
container.stop
|
131
|
+
```
|
132
|
+
|
133
|
+
This example creates a Redis container, connects to it using the `redis` gem, sets and retrieves a key-value pair, and then stops the container.
|
134
|
+
|
135
|
+
### Example with RSpec
|
136
|
+
|
137
|
+
Take a look to the files [examples/redis_container_rspec.rb](https://github.com/guilleiguaran/testcontainers-ruby/blob/main/examples/redis_container_rspec.rb) for a example using RSpec.
|
138
|
+
|
139
|
+
## Contributing
|
140
|
+
|
141
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/guilleiguaran/testcontainers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/guilleiguaran/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).
|
142
|
+
|
143
|
+
## License
|
144
|
+
|
145
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
146
|
+
|
147
|
+
## Code of Conduct
|
148
|
+
|
149
|
+
Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/guilleiguaran/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "standard/rake"
|
13
|
+
|
14
|
+
task default: %i[test standard]
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative "redis/version"
|
2
|
+
require "testcontainers"
|
3
|
+
|
4
|
+
module Testcontainers
|
5
|
+
# RedisContainer class is used to manage containers that run a Redis database
|
6
|
+
#
|
7
|
+
# @attr_reader [String] port used by the container
|
8
|
+
# @attr_reader [String] password used by the container
|
9
|
+
class RedisContainer < ::Testcontainers::DockerContainer
|
10
|
+
# Default port used by the container
|
11
|
+
REDIS_DEFAULT_PORT = 6379
|
12
|
+
|
13
|
+
# Default image used by the container
|
14
|
+
REDIS_DEFAULT_IMAGE = "redis:latest"
|
15
|
+
|
16
|
+
attr_reader :port, :password
|
17
|
+
|
18
|
+
# Initializes a new instance of RedisContainer
|
19
|
+
#
|
20
|
+
# @param image [String] the image to use
|
21
|
+
# @param port [String] the port to use
|
22
|
+
# @param kwargs [Hash] the options to pass to the container. See {DockerContainer#initialize}
|
23
|
+
# @return [RedisContainer] a new instance of RedisContainer
|
24
|
+
def initialize(image = REDIS_DEFAULT_IMAGE, port: nil, **kwargs)
|
25
|
+
super(image, **kwargs)
|
26
|
+
@port = port || ENV.fetch("REDIS_PORT", REDIS_DEFAULT_PORT)
|
27
|
+
@password = password || ENV.fetch("REDIS_PASSWORD", nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Starts the container
|
31
|
+
#
|
32
|
+
# @return [RedisContainer] self
|
33
|
+
def start
|
34
|
+
with_exposed_ports(@port)
|
35
|
+
_configure
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
# Sets the password to use
|
40
|
+
#
|
41
|
+
# @param password [String] the password to use
|
42
|
+
# @return [RedisContainer] self
|
43
|
+
def with_password(password)
|
44
|
+
@password = password
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the Redis connection url (e.g. redis://:password@localhost:6379/0)
|
49
|
+
#
|
50
|
+
# @param protocol [String] the protocol to use in the string (default: "redis")
|
51
|
+
# @return [String] the Redis connection url
|
52
|
+
# @raise [ConnectionError] If the connection to the Docker daemon fails.
|
53
|
+
# @raise [ContainerNotStartedError] If the container has not been started.
|
54
|
+
def redis_url(protocol: "redis", db: 0)
|
55
|
+
if @password.nil? || @password.empty?
|
56
|
+
"#{protocol}://#{host}:#{mapped_port(port)}/#{db}"
|
57
|
+
else
|
58
|
+
"#{protocol}://:#{password}@#{host}:#{mapped_port(port)}/#{db}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
alias_method :database_url, :redis_url
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def _configure
|
67
|
+
add_env("REDIS_PASSWORD", @password) unless @password.nil? || @password.empty?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testcontainers-redis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guillermo Iguaran
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: testcontainers-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-hooks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: standard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: redis
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
description: Testcontainers makes it easy to create and clean up container-based dependencies
|
98
|
+
for automated tests.
|
99
|
+
email:
|
100
|
+
- guilleiguaran@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- CHANGELOG.md
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/testcontainers/redis.rb
|
112
|
+
- lib/testcontainers/redis/version.rb
|
113
|
+
homepage: https://github.com/guilleiguaran/testcontainers-ruby
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata:
|
117
|
+
homepage_uri: https://github.com/guilleiguaran/testcontainers-ruby/blob/main/redis
|
118
|
+
source_code_uri: https://github.com/guilleiguaran/testcontainers-ruby/blob/main/redis
|
119
|
+
changelog_uri: https://github.com/guilleiguaran/testcontainers-ruby/blob/main/redis/CHANGELOG.md
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 2.6.0
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubygems_version: 3.4.1
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: 'Testcontainers for Ruby: Redis module'
|
139
|
+
test_files: []
|