From 18188e9dd27a731f49adb1f74d4c83b7f08a2f7b Mon Sep 17 00:00:00 2001 From: Wil Simpson Date: Fri, 8 Mar 2024 20:08:58 -0500 Subject: [PATCH] Added kafka testing --- coverage.out | 235 ++++++++++++++++++++++++++++------ pkg/mocks/chat_r_mock.go | 39 ++++-- pkg/mocks/chat_s_mock.go | 7 +- pkg/mocks/inventory_r_mock.go | 14 -- pkg/repository/kafka_test.go | 34 ++--- pkg/service/chat_s_test.go | 129 +++++++++++++++++++ test/db/docker.go | 17 ++- 7 files changed, 386 insertions(+), 89 deletions(-) create mode 100644 pkg/service/chat_s_test.go diff --git a/coverage.out b/coverage.out index 0a95356..3fb4c8f 100644 --- a/coverage.out +++ b/coverage.out @@ -47,7 +47,7 @@ github.com/ShatteredRealms/go-backend/pkg/helpers/config.go:45.9,45.23 1 12 github.com/ShatteredRealms/go-backend/pkg/helpers/config.go:45.23,47.4 1 6 github.com/ShatteredRealms/go-backend/pkg/helpers/config.go:49.3,49.54 1 12 github.com/ShatteredRealms/go-backend/pkg/helpers/conversions.go:3.48,5.28 2 1 -github.com/ShatteredRealms/go-backend/pkg/helpers/conversions.go:5.28,7.3 1 37 +github.com/ShatteredRealms/go-backend/pkg/helpers/conversions.go:5.28,7.3 1 78 github.com/ShatteredRealms/go-backend/pkg/helpers/conversions.go:9.2,9.13 1 1 github.com/ShatteredRealms/go-backend/pkg/helpers/errors.go:8.63,9.16 1 4 github.com/ShatteredRealms/go-backend/pkg/helpers/errors.go:9.16,11.3 1 0 @@ -94,9 +94,9 @@ github.com/ShatteredRealms/go-backend/pkg/helpers/srv.go:144.2,144.18 1 2 github.com/ShatteredRealms/go-backend/pkg/helpers/srv.go:144.18,146.3 1 1 github.com/ShatteredRealms/go-backend/pkg/helpers/srv.go:148.2,148.28 1 1 github.com/ShatteredRealms/go-backend/pkg/helpers/uuid.go:9.59,11.39 2 3 -github.com/ShatteredRealms/go-backend/pkg/helpers/uuid.go:11.39,13.17 2 49 +github.com/ShatteredRealms/go-backend/pkg/helpers/uuid.go:11.39,13.17 2 53 github.com/ShatteredRealms/go-backend/pkg/helpers/uuid.go:13.17,15.4 1 2 -github.com/ShatteredRealms/go-backend/pkg/helpers/uuid.go:16.3,16.17 1 47 +github.com/ShatteredRealms/go-backend/pkg/helpers/uuid.go:16.3,16.17 1 51 github.com/ShatteredRealms/go-backend/pkg/helpers/uuid.go:19.2,19.17 1 1 github.com/ShatteredRealms/go-backend/pkg/model/character.go:49.38,50.43 1 10 github.com/ShatteredRealms/go-backend/pkg/model/character.go:50.43,52.3 1 1 @@ -168,6 +168,17 @@ github.com/ShatteredRealms/go-backend/pkg/model/map.go:26.35,28.27 2 12 github.com/ShatteredRealms/go-backend/pkg/model/map.go:28.27,30.3 1 21 github.com/ShatteredRealms/go-backend/pkg/model/map.go:32.2,32.12 1 12 github.com/ShatteredRealms/go-backend/pkg/model/model.go:17.34,19.2 1 2 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:13.31,14.20 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:14.20,16.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:19.111,22.9 3 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:22.9,24.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:26.2,26.50 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:26.50,28.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:30.2,30.15 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:33.93,36.16 3 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:36.16,38.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:40.2,41.12 2 0 +github.com/ShatteredRealms/go-backend/pkg/repository/cacher.go:44.62,47.2 2 0 github.com/ShatteredRealms/go-backend/pkg/repository/character_r.go:32.62,36.2 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/character_r.go:38.101,41.25 3 4 github.com/ShatteredRealms/go-backend/pkg/repository/character_r.go:41.25,44.3 2 0 @@ -206,20 +217,18 @@ github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:63.86,67.2 3 2 github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:69.116,71.2 1 17 github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:73.94,75.2 1 6 github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:77.98,79.2 1 3 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:81.60,83.16 2 1 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:83.16,85.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:87.2,87.74 1 1 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:90.99,93.25 3 10 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:93.25,95.3 1 1 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:97.2,97.30 1 9 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:97.30,99.3 1 8 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:101.2,101.21 1 1 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:104.107,107.25 3 3 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:107.25,109.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:111.2,111.30 1 3 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:111.30,113.3 1 1 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:115.2,115.21 1 2 -github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:118.52,120.2 1 1 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:81.60,83.2 1 1 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:85.99,88.25 3 10 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:88.25,90.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:92.2,92.30 1 9 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:92.30,94.3 1 8 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:96.2,96.21 1 1 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:99.107,102.25 3 3 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:102.25,104.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:106.2,106.30 1 3 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:106.30,108.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:110.2,110.21 1 2 +github.com/ShatteredRealms/go-backend/pkg/repository/chat_r.go:113.52,115.2 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/db.go:19.60,21.16 2 0 github.com/ShatteredRealms/go-backend/pkg/repository/db.go:21.16,23.3 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/db.go:24.2,33.16 6 0 @@ -237,11 +246,11 @@ github.com/ShatteredRealms/go-backend/pkg/repository/db.go:62.2,64.16 3 0 github.com/ShatteredRealms/go-backend/pkg/repository/db.go:64.16,66.3 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/db.go:68.2,68.22 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:69.66,73.2 1 1 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:80.37,81.21 1 26 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:80.37,81.21 1 28 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:81.21,83.3 1 1 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:85.2,90.16 3 25 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:85.2,90.16 3 27 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:90.16,92.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:94.2,94.16 1 25 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:94.2,94.16 1 27 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:98.99,99.15 1 2 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:99.15,101.3 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:103.2,103.75 1 1 @@ -252,14 +261,14 @@ github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:114.25,117 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:119.2,119.30 1 5 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:119.30,122.3 2 1 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:124.2,125.26 2 4 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:135.29,137.16 2 26 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:135.29,137.16 2 28 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:137.16,139.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:141.2,148.100 2 26 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:141.2,148.100 2 28 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:148.100,150.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:152.2,152.23 1 26 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:162.23,170.68 2 26 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:152.2,152.23 1 28 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:162.23,170.68 2 28 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:170.68,172.3 1 1 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:174.2,174.20 1 25 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:174.2,174.20 1 27 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:178.95,180.2 1 3 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:183.95,185.2 1 2 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:188.89,190.2 1 2 @@ -307,7 +316,7 @@ github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:321.30,323 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:325.2,325.15 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:329.118,332.2 2 3 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:335.118,338.2 2 3 -github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:341.106,344.2 2 26 +github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:341.106,344.2 2 28 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:347.106,350.2 2 3 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:353.123,364.2 2 3 github.com/ShatteredRealms/go-backend/pkg/repository/gamebackend_r.go:367.77,368.16 1 2 @@ -320,25 +329,179 @@ github.com/ShatteredRealms/go-backend/pkg/repository/inventory_r.go:30.16,32.3 1 github.com/ShatteredRealms/go-backend/pkg/repository/inventory_r.go:34.2,34.23 1 4 github.com/ShatteredRealms/go-backend/pkg/repository/inventory_r.go:38.111,41.2 2 5 github.com/ShatteredRealms/go-backend/pkg/repository/inventory_r.go:43.71,45.2 1 11 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:21.70,22.24 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:21.70,22.24 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:22.24,24.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:25.2,25.27 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:25.2,25.27 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:25.27,27.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:28.2,30.27 2 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:30.27,33.3 2 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:34.2,34.16 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:28.2,30.27 2 1 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:30.27,33.3 2 1 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:34.2,34.16 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:34.16,36.3 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:38.2,39.16 2 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:39.16,40.29 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:40.29,42.4 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:38.2,39.16 2 1 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:39.16,40.29 1 1 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:40.29,42.4 1 1 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:43.3,43.48 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:46.2,46.27 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:46.27,49.3 2 0 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:50.2,50.16 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:50.16,52.3 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:54.2,54.28 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:57.35,61.46 4 0 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:57.35,61.46 4 1 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:61.46,62.39 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:62.39,64.4 1 0 github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:66.3,66.13 1 0 -github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:69.2,69.12 1 0 +github.com/ShatteredRealms/go-backend/pkg/repository/kafka.go:69.2,69.12 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:32.98,34.2 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:39.29,42.16 2 18 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:42.16,44.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:46.2,48.8 1 17 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:51.139,60.45 2 2 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:60.45,62.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:64.2,64.39 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:67.92,69.2 1 8 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:71.115,75.48 3 5 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:76.30,77.59 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:78.32,79.57 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:80.10,82.37 2 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:85.2,85.16 1 4 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:85.16,87.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:89.2,90.32 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:90.32,92.3 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:93.2,94.32 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:94.32,96.3 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:98.2,98.39 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:98.39,100.3 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:102.2,103.31 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:103.31,105.3 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:107.2,108.30 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:108.30,110.3 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:112.2,113.39 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:113.39,115.3 1 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:117.2,118.16 2 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:118.16,120.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:122.2,122.43 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:125.70,127.16 2 3 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:127.16,129.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:131.2,131.22 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:131.22,133.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:135.2,135.38 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:138.82,140.2 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:142.103,144.2 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:146.109,148.16 2 2 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:148.16,150.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/character_s.go:152.2,155.32 3 1 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:49.132,51.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:53.120,55.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:57.123,62.16 4 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:62.16,64.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:66.2,66.33 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:66.33,68.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:70.2,70.38 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:70.38,72.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:74.2,74.47 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:77.91,79.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:81.95,94.2 5 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:96.100,109.2 5 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:110.122,114.23 3 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:114.23,116.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:118.2,125.3 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:128.133,132.23 3 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:132.23,134.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:135.2,142.3 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:145.83,147.2 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:149.113,151.16 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:151.16,153.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:155.2,156.24 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:159.91,161.16 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:161.16,163.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:165.2,167.12 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:170.134,175.16 4 4 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:175.16,177.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:179.2,180.16 2 3 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:180.16,182.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:184.2,192.16 3 2 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:192.16,194.3 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:196.2,198.37 2 1 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:198.37,200.3 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:202.2,203.16 2 1 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:203.16,205.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:207.2,207.21 1 1 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:210.81,216.2 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:218.50,220.2 1 2 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:222.48,224.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:226.97,230.47 3 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:230.47,237.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:239.2,239.43 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:242.95,246.45 3 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:246.45,253.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/chat_s.go:255.2,255.41 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:79.31,81.16 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:81.16,83.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:85.2,87.8 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:95.37,97.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:100.141,102.15 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:102.15,104.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:106.2,106.33 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:106.33,109.3 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:112.2,113.43 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:113.43,117.3 3 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:119.2,120.16 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:124.160,126.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:129.142,131.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:134.92,136.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:139.92,141.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:144.86,146.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:149.86,151.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:154.127,156.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:159.125,163.48 3 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:164.30,166.17 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:166.17,168.4 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:169.3,169.56 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:170.32,171.66 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:172.10,174.37 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:177.2,177.16 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:177.16,179.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:181.2,181.33 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:181.33,183.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:185.2,185.36 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:185.36,187.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:189.2,189.37 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:189.37,191.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:193.2,193.22 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:193.22,195.17 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:195.17,197.4 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:199.3,200.17 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:200.17,202.4 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:204.3,204.31 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:207.2,207.63 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:211.107,215.48 3 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:216.24,218.17 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:218.17,220.4 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:221.3,221.44 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:222.26,223.54 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:224.10,226.37 2 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:229.2,229.16 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:229.16,231.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:233.2,233.33 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:233.33,235.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:237.2,237.33 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:237.33,239.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:241.2,241.39 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:241.39,243.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:245.2,245.38 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:245.38,247.3 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:249.2,249.51 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:253.95,255.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:258.83,260.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:263.110,265.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:268.110,270.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:273.115,275.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:278.115,280.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:283.120,285.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:288.98,290.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:293.98,295.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:298.103,300.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/gamebackend_s.go:303.103,305.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/inventory_s.go:19.80,23.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/inventory_s.go:26.115,28.2 1 0 +github.com/ShatteredRealms/go-backend/pkg/service/inventory_s.go:31.108,33.2 1 0 diff --git a/pkg/mocks/chat_r_mock.go b/pkg/mocks/chat_r_mock.go index 7d2575d..575f758 100644 --- a/pkg/mocks/chat_r_mock.go +++ b/pkg/mocks/chat_r_mock.go @@ -113,6 +113,21 @@ func (mr *MockChatRepositoryMockRecorder) DeleteChannel(ctx, channel any) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteChannel", reflect.TypeOf((*MockChatRepository)(nil).DeleteChannel), ctx, channel) } +// FindChannelById mocks base method. +func (m *MockChatRepository) FindChannelById(ctx context.Context, id uint) (*model.ChatChannel, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindChannelById", ctx, id) + ret0, _ := ret[0].(*model.ChatChannel) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FindChannelById indicates an expected call of FindChannelById. +func (mr *MockChatRepositoryMockRecorder) FindChannelById(ctx, id any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindChannelById", reflect.TypeOf((*MockChatRepository)(nil).FindChannelById), ctx, id) +} + // FindDeletedWithName mocks base method. func (m *MockChatRepository) FindDeletedWithName(ctx context.Context, name string) (*model.ChatChannel, error) { m.ctrl.T.Helper() @@ -128,19 +143,18 @@ func (mr *MockChatRepositoryMockRecorder) FindDeletedWithName(ctx, name any) *go return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindDeletedWithName", reflect.TypeOf((*MockChatRepository)(nil).FindDeletedWithName), ctx, name) } -// GetChannel mocks base method. -func (m *MockChatRepository) GetChannel(ctx context.Context, id uint) (*model.ChatChannel, error) { +// FullDeleteChannel mocks base method. +func (m *MockChatRepository) FullDeleteChannel(ctx context.Context, channel *model.ChatChannel) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetChannel", ctx, id) - ret0, _ := ret[0].(*model.ChatChannel) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret := m.ctrl.Call(m, "FullDeleteChannel", ctx, channel) + ret0, _ := ret[0].(error) + return ret0 } -// GetChannel indicates an expected call of GetChannel. -func (mr *MockChatRepositoryMockRecorder) GetChannel(ctx, id any) *gomock.Call { +// FullDeleteChannel indicates an expected call of FullDeleteChannel. +func (mr *MockChatRepositoryMockRecorder) FullDeleteChannel(ctx, channel any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChannel", reflect.TypeOf((*MockChatRepository)(nil).GetChannel), ctx, id) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FullDeleteChannel", reflect.TypeOf((*MockChatRepository)(nil).FullDeleteChannel), ctx, channel) } // Migrate mocks base method. @@ -158,11 +172,12 @@ func (mr *MockChatRepositoryMockRecorder) Migrate(ctx any) *gomock.Call { } // UpdateChannel mocks base method. -func (m *MockChatRepository) UpdateChannel(ctx context.Context, channel *model.ChatChannel) error { +func (m *MockChatRepository) UpdateChannel(ctx context.Context, channel *model.ChatChannel) (*model.ChatChannel, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateChannel", ctx, channel) - ret0, _ := ret[0].(error) - return ret0 + ret0, _ := ret[0].(*model.ChatChannel) + ret1, _ := ret[1].(error) + return ret0, ret1 } // UpdateChannel indicates an expected call of UpdateChannel. diff --git a/pkg/mocks/chat_s_mock.go b/pkg/mocks/chat_s_mock.go index 2f3bd7e..2daaafc 100644 --- a/pkg/mocks/chat_s_mock.go +++ b/pkg/mocks/chat_s_mock.go @@ -187,11 +187,12 @@ func (mr *MockChatServiceMockRecorder) SendDirectMessage(ctx, senderCharacter, m } // UpdateChannel mocks base method. -func (m *MockChatService) UpdateChannel(ctx context.Context, pb *pb.UpdateChatChannelRequest) error { +func (m *MockChatService) UpdateChannel(ctx context.Context, pb *pb.UpdateChatChannelRequest) (*model.ChatChannel, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateChannel", ctx, pb) - ret0, _ := ret[0].(error) - return ret0 + ret0, _ := ret[0].(*model.ChatChannel) + ret1, _ := ret[1].(error) + return ret0, ret1 } // UpdateChannel indicates an expected call of UpdateChannel. diff --git a/pkg/mocks/inventory_r_mock.go b/pkg/mocks/inventory_r_mock.go index cb999be..e4761cd 100644 --- a/pkg/mocks/inventory_r_mock.go +++ b/pkg/mocks/inventory_r_mock.go @@ -55,20 +55,6 @@ func (mr *MockInventoryRepositoryMockRecorder) GetInventory(ctx, characterId any return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInventory", reflect.TypeOf((*MockInventoryRepository)(nil).GetInventory), ctx, characterId) } -// Migrate mocks base method. -func (m *MockInventoryRepository) Migrate(ctx context.Context) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Migrate", ctx) - ret0, _ := ret[0].(error) - return ret0 -} - -// Migrate indicates an expected call of Migrate. -func (mr *MockInventoryRepositoryMockRecorder) Migrate(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Migrate", reflect.TypeOf((*MockInventoryRepository)(nil).Migrate), ctx) -} - // UpdateInventory mocks base method. func (m *MockInventoryRepository) UpdateInventory(ctx context.Context, inventory *model.CharacterInventory) error { m.ctrl.T.Helper() diff --git a/pkg/repository/kafka_test.go b/pkg/repository/kafka_test.go index 1b52926..73c6f54 100644 --- a/pkg/repository/kafka_test.go +++ b/pkg/repository/kafka_test.go @@ -1,31 +1,31 @@ package repository_test import ( - // "strconv" + "strconv" . "github.com/onsi/ginkgo/v2" - // . "github.com/onsi/gomega" - // - // "github.com/ShatteredRealms/go-backend/pkg/config" - // "github.com/ShatteredRealms/go-backend/pkg/repository" - // testdb "github.com/ShatteredRealms/go-backend/test/db" + . "github.com/onsi/gomega" + + "github.com/ShatteredRealms/go-backend/pkg/config" + "github.com/ShatteredRealms/go-backend/pkg/repository" + testdb "github.com/ShatteredRealms/go-backend/test/db" ) var _ = Describe("Kafka repository", func() { Describe("ConnectKafka", func() { Context("valid input", func() { It("should work", func() { - // cleanupFunc, _, kResource := testdb.SetupKafkaWithDocker() - // sPort := kResource.GetPort("29092/tcp") - // port, err := strconv.ParseUint(sPort, 10, 64) - // Expect(err).NotTo(HaveOccurred()) - // kafka, err := repository.ConnectKafka(config.ServerAddress{ - // Port: uint(port), - // Host: "127.0.0.1", - // }) - // Expect(err).NotTo(HaveOccurred()) - // Expect(kafka).NotTo(BeNil()) - // cleanupFunc() + cleanupFunc, _, kResource := testdb.SetupKafkaWithDocker() + defer cleanupFunc() + sPort := kResource.GetPort("29093/tcp") + port, err := strconv.ParseUint(sPort, 10, 64) + Expect(err).NotTo(HaveOccurred()) + kafka, err := repository.ConnectKafka(config.ServerAddress{ + Port: uint(port), + Host: "127.0.0.1", + }) + Expect(err).NotTo(HaveOccurred()) + Expect(kafka).NotTo(BeNil()) }) }) }) diff --git a/pkg/service/chat_s_test.go b/pkg/service/chat_s_test.go new file mode 100644 index 0000000..cd18c86 --- /dev/null +++ b/pkg/service/chat_s_test.go @@ -0,0 +1,129 @@ +package service_test + +import ( + "context" + "fmt" + "strconv" + "time" + + "github.com/ShatteredRealms/go-backend/pkg/config" + "github.com/ShatteredRealms/go-backend/pkg/mocks" + "github.com/ShatteredRealms/go-backend/pkg/model" + "github.com/ShatteredRealms/go-backend/pkg/service" + testdb "github.com/ShatteredRealms/go-backend/test/db" + "github.com/bxcodec/faker/v4" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/ory/dockertest/v3" + "github.com/sirupsen/logrus/hooks/test" + "go.uber.org/mock/gomock" + "gorm.io/gorm" +) + +var _ = Describe("Chat service", Ordered, func() { + + var ( + hook *test.Hook + + mockController *gomock.Controller + mockRepository *mocks.MockChatRepository + cleanupFunc func() + kResource *dockertest.Resource + + chatService service.ChatService + + kafkaPort uint + + err error + fakeError = fmt.Errorf("error") + channels = []*model.ChatChannel{ + { + Model: gorm.Model{ + ID: 1, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + }, + Name: faker.Username(), + Dimension: faker.Username(), + }, + { + Model: gorm.Model{ + ID: 2, + CreatedAt: time.Now().Add(time.Minute), + UpdatedAt: time.Now().Add(time.Minute), + }, + Name: faker.Username(), + Dimension: faker.Username(), + }, + } + ) + + BeforeAll(func() { + _, hook = test.NewNullLogger() + mockController = gomock.NewController(GinkgoT()) + mockRepository = mocks.NewMockChatRepository(mockController) + + cleanupFunc, _, kResource = testdb.SetupKafkaWithDocker() + sPort := kResource.GetPort("29093/tcp") + port, err := strconv.ParseUint(sPort, 10, 64) + kafkaPort = uint(port) + Expect(err).NotTo(HaveOccurred()) + hook.Reset() + }) + + Describe("NewChatService", Ordered, func() { + When("given invalid input", func() { + It("should fail if migration fails", func() { + mockRepository.EXPECT().Migrate(gomock.Any()).Return(fakeError) + chatService, err = service.NewChatService(context.Background(), mockRepository, config.ServerAddress{ + Port: kafkaPort, + Host: "localhost", + }) + + Expect(err).To(MatchError(fakeError)) + Expect(chatService).To(BeNil()) + }) + + It("should fail if kafka connect fails", func() { + mockRepository.EXPECT().Migrate(gomock.Any()).Return(nil) + chatService, err = service.NewChatService(context.Background(), mockRepository, config.ServerAddress{ + Port: 0, + Host: "nowhere", + }) + + Expect(err).To(HaveOccurred()) + Expect(chatService).To(BeNil()) + }) + + It("should fail if kafka all channels", func() { + mockRepository.EXPECT().Migrate(gomock.Any()).Return(nil) + mockRepository.EXPECT().AllChannels(gomock.Any()).Return(model.ChatChannels{}, fakeError) + chatService, err = service.NewChatService(context.Background(), mockRepository, config.ServerAddress{ + Port: kafkaPort, + Host: "localhost", + }) + + Expect(err).To(HaveOccurred()) + Expect(chatService).To(BeNil()) + }) + }) + + When("valid input is given", func() { + It("should succeed", func() { + mockRepository.EXPECT().Migrate(gomock.Any()).Return(nil) + mockRepository.EXPECT().AllChannels(gomock.Any()).Return(channels, nil) + chatService, err = service.NewChatService(context.Background(), mockRepository, config.ServerAddress{ + Port: kafkaPort, + Host: "localhost", + }) + + Expect(err).To(BeNil()) + Expect(chatService).NotTo(BeNil()) + }) + }) + }) + + AfterAll(func() { + cleanupFunc() + }) +}) diff --git a/test/db/docker.go b/test/db/docker.go index 8ec3387..05f2bdc 100644 --- a/test/db/docker.go +++ b/test/db/docker.go @@ -53,16 +53,16 @@ func SetupKafkaWithDocker() (func(), *dockertest.Resource, *dockertest.Resource) Env: []string{ "KAFKA_BROKER_ID=1", "KAFKA_ZOOKEEPER_CONNECT=gozookeeper:2181", - "KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://gokafka:9092,PLAINTEXT_HOST://gokafka:29092", + "KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9093,PLAINTEXT_HOST://localhost:29093", "KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT", "KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT", // "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1", }, PortBindings: map[docker.Port][]docker.PortBinding{ - "39092/tcp": {{HostIP: "gokafka", HostPort: "29092/tcp"}}, - "49092/tcp": {{HostIP: "gokafka", HostPort: "9092/tcp"}}, + "29093/tcp": {{HostIP: "localhost", HostPort: "29093/tcp"}}, + "9093/tcp": {{HostIP: "localhost", HostPort: "9093/tcp"}}, }, - ExposedPorts: []string{"29092/tcp"}, + ExposedPorts: []string{"29093/tcp"}, Networks: []*dockertest.Network{net}, } @@ -85,9 +85,12 @@ func SetupKafkaWithDocker() (func(), *dockertest.Resource, *dockertest.Resource) })) fnCleanup := func() { - chk(kafkaResource.Close()) - chk(zookeeperResource.Close()) - chk(net.Close()) + err1 := kafkaResource.Close() + err2 := zookeeperResource.Close() + err3 := net.Close() + chk(err1) + chk(err2) + chk(err3) } return fnCleanup, zookeeperResource, kafkaResource