From 9f2e6a1f871ccacf716b00050bc33d34f5c1b187 Mon Sep 17 00:00:00 2001 From: munishchouhan Date: Thu, 24 Oct 2024 10:49:24 +0200 Subject: [PATCH] added tests Signed-off-by: munishchouhan --- .../seqera/wave/redis/RedisFactoryTest.groovy | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/test/groovy/io/seqera/wave/redis/RedisFactoryTest.groovy diff --git a/src/test/groovy/io/seqera/wave/redis/RedisFactoryTest.groovy b/src/test/groovy/io/seqera/wave/redis/RedisFactoryTest.groovy new file mode 100644 index 000000000..f489d94d4 --- /dev/null +++ b/src/test/groovy/io/seqera/wave/redis/RedisFactoryTest.groovy @@ -0,0 +1,48 @@ +/* + * Wave, containers provisioning service + * Copyright (c) 2023-2024, Seqera Labs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package io.seqera.wave.redis + +import spock.lang.Specification + +import redis.clients.jedis.HostAndPort +/** + * + * @author Munish Chouhan + */ +class RedisFactoryTest extends Specification { + def 'should build address' () { + expect: + RedisFactory.buildHostAndPort(ADDR) == EXPECTED + + where: + ADDR | EXPECTED + 'foo' | new HostAndPort('foo', 6379) + 'bar.com:5000' | new HostAndPort('bar.com', 5000) + 'redis://bar.com:1234' | new HostAndPort('bar.com', 1234) + 'rediss://bar.com:1234' | new HostAndPort('bar.com', 1234) + } + + def 'should report and error' () { + when: + RedisFactory.buildHostAndPort('http://foo') + then: + def e = thrown(IllegalArgumentException) + e.message == "Invalid Redis address: 'http://foo' - it should match the regex (rediss?://)?(?[^:]+)(:(?\\d+))?" + } +}