Skip to content

Commit

Permalink
test: cd 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
songyi00 committed Jul 22, 2024
1 parent 843644e commit 9c32d0b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feat/#6-ci-cd

jobs:
build-and-push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
package com.nexters.goalpanzi.domain.auth;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;

import static org.assertj.core.api.Assertions.assertThat;

@DataRedisTest
public class RefreshTokenRepositoryTest {

@Autowired
private RefreshTokenRepository refreshTokenRepository;

@Autowired
private RedisTemplate<String, String> redisTemplate;

@TestConfiguration
static class RedisTestConfig {
@Bean
public RefreshTokenRepository refreshTokenRepository(RedisTemplate<String, String> redisTemplate) {
return new RefreshTokenRepository(redisTemplate);
}
}

@BeforeEach
public void setUp() {
redisTemplate.getConnectionFactory().getConnection().serverCommands().flushAll();
}

@Test
void 키에_해당하는_refresh_토큰을_조회한다() {
refreshTokenRepository.save("altKey", "refreshToken", 60000);

String foundToken = refreshTokenRepository.find("altKey");

assertThat(foundToken).isEqualTo("refreshToken");
}

@Test
void 키가_존재하지_않는_경우_Null을_반환한다() {
String foundToken = refreshTokenRepository.find("altKey");

assertThat(foundToken).isNull();
}

@Test
void 키에_해당하는_refresh_토큰을_삭제한다() {
refreshTokenRepository.save("altKey", "refreshToken", 60000);

Boolean deleteResult = refreshTokenRepository.delete("altKey");

assertThat(deleteResult).isTrue();
}

@Test
void refresh_토큰을_갱신한다() {
refreshTokenRepository.save("altKey", "refreshToken", 60000);
refreshTokenRepository.save("altKey", "revisedRefreshToken", 60000);

String foundToken = refreshTokenRepository.find("altKey");

assertThat(foundToken).isEqualTo("revisedRefreshToken");
}

@Test
void ttl이_만료되어_refresh_토큰을_조회할_수_없다() throws InterruptedException {
refreshTokenRepository.save("altKey", "refreshToken", 100);

Thread.sleep(100);
String foundToken = refreshTokenRepository.find("altKey");

assertThat(foundToken).isNull();
}
}
//package com.nexters.goalpanzi.domain.auth;
//
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
//import org.springframework.boot.test.context.TestConfiguration;
//import org.springframework.context.annotation.Bean;
//import org.springframework.data.redis.core.RedisTemplate;
//
//import static org.assertj.core.api.Assertions.assertThat;
//
//@DataRedisTest
//public class RefreshTokenRepositoryTest {
//
// @Autowired
// private RefreshTokenRepository refreshTokenRepository;
//
// @Autowired
// private RedisTemplate<String, String> redisTemplate;
//
// @TestConfiguration
// static class RedisTestConfig {
// @Bean
// public RefreshTokenRepository refreshTokenRepository(RedisTemplate<String, String> redisTemplate) {
// return new RefreshTokenRepository(redisTemplate);
// }
// }
//
// @BeforeEach
// public void setUp() {
// redisTemplate.getConnectionFactory().getConnection().serverCommands().flushAll();
// }
//
// @Test
// void 키에_해당하는_refresh_토큰을_조회한다() {
// refreshTokenRepository.save("altKey", "refreshToken", 60000);
//
// String foundToken = refreshTokenRepository.find("altKey");
//
// assertThat(foundToken).isEqualTo("refreshToken");
// }
//
// @Test
// void 키가_존재하지_않는_경우_Null을_반환한다() {
// String foundToken = refreshTokenRepository.find("altKey");
//
// assertThat(foundToken).isNull();
// }
//
// @Test
// void 키에_해당하는_refresh_토큰을_삭제한다() {
// refreshTokenRepository.save("altKey", "refreshToken", 60000);
//
// Boolean deleteResult = refreshTokenRepository.delete("altKey");
//
// assertThat(deleteResult).isTrue();
// }
//
// @Test
// void refresh_토큰을_갱신한다() {
// refreshTokenRepository.save("altKey", "refreshToken", 60000);
// refreshTokenRepository.save("altKey", "revisedRefreshToken", 60000);
//
// String foundToken = refreshTokenRepository.find("altKey");
//
// assertThat(foundToken).isEqualTo("revisedRefreshToken");
// }
//
// @Test
// void ttl이_만료되어_refresh_토큰을_조회할_수_없다() throws InterruptedException {
// refreshTokenRepository.save("altKey", "refreshToken", 100);
//
// Thread.sleep(100);
// String foundToken = refreshTokenRepository.find("altKey");
//
// assertThat(foundToken).isNull();
// }
//}

0 comments on commit 9c32d0b

Please sign in to comment.