From bdb422a0f7dab47e4212d32984fe3a0f6a281aa2 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Sun, 21 Apr 2024 11:28:34 +0200
Subject: [PATCH] fix: fixing test cases #57

---
 .idea/workspace.xml       | 47 +++++++++++++++++++--------------------
 database-6_test.go        |  2 +-
 issue-1_test.go           |  4 +++-
 manager.go                |  2 +-
 nix/scripts/go-task.nix   |  2 +-
 nix/scripts/run-tests.nix |  6 ++---
 6 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bccf6a0..6255d27 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,18 +6,9 @@
   <component name="ChangeListManager">
     <list default="true" id="9979eb22-471e-4f2f-b624-fd3edb5e8c6e" name="Changes" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database-1_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-1_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database-2_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-2_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database-3_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-3_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database-4_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-4_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database-5_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-5_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database-7_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-7_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database-8_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-8_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database.go" beforeDir="false" afterPath="$PROJECT_DIR$/database.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/database_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/job-syncer.go" beforeDir="false" afterPath="$PROJECT_DIR$/job-syncer.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/job-syncer_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/job-syncer_test.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/nix/scripts/go-task.nix" beforeDir="false" afterPath="$PROJECT_DIR$/nix/scripts/go-task.nix" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/database-6_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-6_test.go" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/issue-1_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/issue-1_test.go" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/manager.go" beforeDir="false" afterPath="$PROJECT_DIR$/manager.go" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/nix/scripts/run-tests.nix" beforeDir="false" afterPath="$PROJECT_DIR$/nix/scripts/run-tests.nix" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
@@ -58,11 +49,13 @@
     "DefaultGoTemplateProperty": "Go File",
     "Go Test.TestDummyRunnable in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "Go Test.TestResetStats in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
+    "Go Test.TestRoundTrip in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "Go Test.TestScheduleJob in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "Go Test.TestStructure in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "Go Test.TestTimeFunctionSame in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "Go Test.TestWriteToDB1 in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "Go Test.TestWriteToDB2 in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
+    "Go Test.TestWriteToDB4 in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "Go Test.go test gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
     "RunOnceActivity.ShowReadmeOnStart": "true",
     "RunOnceActivity.go.formatter.settings.were.checked": "true",
@@ -90,7 +83,7 @@
       <recent name="$PROJECT_DIR$/.back" />
     </key>
   </component>
-  <component name="RunManager" selected="Go Test.TestWriteToDB1 in gitlab.schukai.com/oss/libraries/go/services/job-queues">
+  <component name="RunManager" selected="Go Test.TestRoundTrip in gitlab.schukai.com/oss/libraries/go/services/job-queues">
     <configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
       <module name="job-queues" />
       <working_directory value="$PROJECT_DIR$" />
@@ -111,7 +104,7 @@
       <pattern value="^\QTestDummyRunnable\E$" />
       <method v="2" />
     </configuration>
-    <configuration name="TestResetStats in gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
+    <configuration name="TestRoundTrip in gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
       <module name="job-queues" />
       <working_directory value="$PROJECT_DIR$" />
       <kind value="PACKAGE" />
@@ -119,7 +112,7 @@
       <directory value="$PROJECT_DIR$" />
       <filePath value="$PROJECT_DIR$" />
       <framework value="gotest" />
-      <pattern value="^\QTestResetStats\E$" />
+      <pattern value="^\QTestRoundTrip\E$" />
       <method v="2" />
     </configuration>
     <configuration name="TestWriteToDB1 in gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
@@ -144,21 +137,22 @@
       <pattern value="^\QTestWriteToDB2\E$" />
       <method v="2" />
     </configuration>
-    <configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
+    <configuration name="TestWriteToDB4 in gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
       <module name="job-queues" />
       <working_directory value="$PROJECT_DIR$" />
-      <go_parameters value="-i" />
-      <kind />
+      <kind value="PACKAGE" />
+      <package value="gitlab.schukai.com/oss/libraries/go/services/job-queues" />
       <directory value="$PROJECT_DIR$" />
       <filePath value="$PROJECT_DIR$" />
       <framework value="gotest" />
+      <pattern value="^\QTestWriteToDB4\E$" />
       <method v="2" />
     </configuration>
-    <configuration name="go test gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
+    <configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
       <module name="job-queues" />
       <working_directory value="$PROJECT_DIR$" />
-      <kind value="PACKAGE" />
-      <package value="gitlab.schukai.com/oss/libraries/go/services/job-queues" />
+      <go_parameters value="-i" />
+      <kind />
       <directory value="$PROJECT_DIR$" />
       <filePath value="$PROJECT_DIR$" />
       <framework value="gotest" />
@@ -166,11 +160,11 @@
     </configuration>
     <recent_temporary>
       <list>
+        <item itemvalue="Go Test.TestRoundTrip in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
+        <item itemvalue="Go Test.TestWriteToDB4 in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
         <item itemvalue="Go Test.TestWriteToDB1 in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
         <item itemvalue="Go Test.TestWriteToDB2 in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
         <item itemvalue="Go Test.TestDummyRunnable in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
-        <item itemvalue="Go Test.go test gitlab.schukai.com/oss/libraries/go/services/job-queues" />
-        <item itemvalue="Go Test.TestResetStats in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
       </list>
     </recent_temporary>
   </component>
@@ -206,7 +200,7 @@
         </line-breakpoint>
         <line-breakpoint enabled="true" type="DlvLineBreakpoint">
           <url>file://$PROJECT_DIR$/database-2_test.go</url>
-          <line>25</line>
+          <line>32</line>
           <option name="timeStamp" value="20" />
         </line-breakpoint>
         <line-breakpoint enabled="true" type="DlvLineBreakpoint">
@@ -214,6 +208,11 @@
           <line>70</line>
           <option name="timeStamp" value="21" />
         </line-breakpoint>
+        <line-breakpoint enabled="true" type="DlvLineBreakpoint">
+          <url>file://$PROJECT_DIR$/job-syncer.go</url>
+          <line>62</line>
+          <option name="timeStamp" value="23" />
+        </line-breakpoint>
       </breakpoints>
     </breakpoint-manager>
   </component>
diff --git a/database-6_test.go b/database-6_test.go
index 09c9a5c..d73048a 100644
--- a/database-6_test.go
+++ b/database-6_test.go
@@ -18,7 +18,7 @@ func TestWriteToDB6(t *testing.T) {
 	// it is necessary to have a running mysql server
 	// docker rm -f mysql-test && \
 	// docker run --name mysql-test -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=testdb -p 3306:3306 -d mysql:latest && \
-	// docker logs -f  mysql-test
+	// docker logs -f mysql-test
 
 	//dsn := "root:my-secret-pw@tcp(localhost:3306)/testdb?charset=utf8mb4&parseTime=True&loc=Local"
 	//db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
diff --git a/issue-1_test.go b/issue-1_test.go
index 1915a4c..2b94af8 100644
--- a/issue-1_test.go
+++ b/issue-1_test.go
@@ -16,7 +16,7 @@ import (
 )
 
 // TestRoundTrip tests the round trip of jobs from yaml to the manager and back to yaml
-// This test runs forever and must be stopped manually
+// This test runs forever and must be stopped manually. this test run without database
 // Use the following command to run this test:
 // go test -timeout 6h -run TestRoundTrip -v
 func TestRoundTrip(t *testing.T) {
@@ -63,6 +63,8 @@ func TestRoundTrip(t *testing.T) {
 
 	var err error
 
+	t.Log("This test runs forever and must be stopped manually")
+
 	cronInstance := cron.New(cron.WithSeconds())
 	cronInstance.Start()
 
diff --git a/manager.go b/manager.go
index 405d327..657d3bd 100644
--- a/manager.go
+++ b/manager.go
@@ -467,7 +467,7 @@ func (m *Manager) Start() error {
 		return ErrManagerAlreadyRunning
 	}
 
-	if m.jobSyncer == nil {
+	if m.jobSyncer == nil && m.database != nil {
 		m.jobSyncer = NewJobSyncer(m)
 	}
 
diff --git a/nix/scripts/go-task.nix b/nix/scripts/go-task.nix
index 406aeac..15c7eb2 100644
--- a/nix/scripts/go-task.nix
+++ b/nix/scripts/go-task.nix
@@ -13,7 +13,7 @@
           - rt
         env:
           TEST_BY_TASK: true
-          USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"        
+          USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
         cmds:
           - run-tests
         silent: true
diff --git a/nix/scripts/run-tests.nix b/nix/scripts/run-tests.nix
index befcdfa..bad5005 100644
--- a/nix/scripts/run-tests.nix
+++ b/nix/scripts/run-tests.nix
@@ -24,7 +24,7 @@ in
 
     if [[ "$selection" == "run all tests" ]]; then
       echo_ok "Running all tests"
-      if ! ${pkgs.go}/bin/go test -v -failfast ./...
+      if ! ${pkgs.go}/bin/go test -tags runOnTask -v -failfast ./...
       then
         echo_fail "ERROR: Tests failed, check your Go!"
         exit 1
@@ -52,8 +52,8 @@ in
         echo_ok "No tests selected, exiting."
         exit 0
     fi
-    
-    if ! ${pkgs.go}/bin/go test -run "$(echo $selected_tests | tr '\n' "")"
+
+    if ! ${pkgs.go}/bin/go test -tags runOnTask -run "$(echo $selected_tests)"
     then
       echo_fail "ERROR: Tests failed, check your Go!"
       exit 1
-- 
GitLab