Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.10.1
  • v1.10.2
  • v1.11.0
  • v1.12.0
  • v1.12.1
  • v1.12.2
  • v1.12.3
  • v1.12.4
  • v1.12.5
  • v1.12.6
  • v1.12.7
  • v1.12.8
  • v1.13.0
  • v1.13.1
  • v1.13.2
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.15.10
  • v1.15.11
  • v1.15.12
  • v1.15.13
  • v1.15.14
  • v1.15.15
  • v1.15.16
  • v1.15.17
  • v1.15.2
  • v1.15.3
  • v1.15.4
  • v1.15.5
  • v1.15.6
  • v1.15.7
  • v1.15.8
  • v1.15.9
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.19.0
  • v1.19.1
  • v1.19.2
  • v1.19.3
  • v1.19.4
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.4.0
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.7.1
  • v1.7.2
  • v1.7.3
  • v1.8.0
  • v1.8.1
  • v1.9.0
76 results

Target

Select target project
  • oss/libraries/go/services/job-queues
1 result
Select Git revision
  • master
  • v1.0.0
  • v1.0.1
  • v1.1.0
  • v1.10.0
  • v1.10.1
  • v1.10.2
  • v1.11.0
  • v1.12.0
  • v1.12.1
  • v1.12.2
  • v1.12.3
  • v1.12.4
  • v1.12.5
  • v1.12.6
  • v1.12.7
  • v1.12.8
  • v1.13.0
  • v1.13.1
  • v1.13.2
  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.15.10
  • v1.15.11
  • v1.15.12
  • v1.15.13
  • v1.15.14
  • v1.15.15
  • v1.15.16
  • v1.15.17
  • v1.15.2
  • v1.15.3
  • v1.15.4
  • v1.15.5
  • v1.15.6
  • v1.15.7
  • v1.15.8
  • v1.15.9
  • v1.16.0
  • v1.16.1
  • v1.17.0
  • v1.18.0
  • v1.18.1
  • v1.18.2
  • v1.19.0
  • v1.19.1
  • v1.19.2
  • v1.19.3
  • v1.19.4
  • v1.2.0
  • v1.20.0
  • v1.20.1
  • v1.20.2
  • v1.20.3
  • v1.21.0
  • v1.21.1
  • v1.22.0
  • v1.23.0
  • v1.23.1
  • v1.23.2
  • v1.3.0
  • v1.3.1
  • v1.3.2
  • v1.4.0
  • v1.5.0
  • v1.5.1
  • v1.6.0
  • v1.6.1
  • v1.7.0
  • v1.7.1
  • v1.7.2
  • v1.7.3
  • v1.8.0
  • v1.8.1
  • v1.9.0
76 results
Show changes
Commits on Source (2)
......@@ -49,4 +49,5 @@ var (
ErrCannotLoadStatsFromDatabase = fmt.Errorf("errors while loading stats from database")
ErrInvalidTime = fmt.Errorf("invalid time")
ErrSchedulerMisconfiguration = fmt.Errorf("scheduler misconfiguration")
ErrInvalidDuration = fmt.Errorf("invalid duration")
)
// Copyright 2023 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0
package jobqueue
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
"time"
)
// TestUnmarshalYAML tests the unmarshalling of the SchedulerPersistence struct
func TestUnmarshalYAML(t *testing.T) {
yamlStr := `
time: "2023-12-06T15:04:05Z"
interval: "1h30m"
`
sp := SchedulerPersistence{}
err := yaml.Unmarshal([]byte(yamlStr), &sp)
assert.NoError(t, err)
expectedTime, _ := time.Parse(time.RFC3339, "2023-12-06T15:04:05Z")
assert.Equal(t, expectedTime, *sp.Time, "the time should be parsed correctly")
expectedInterval, _ := time.ParseDuration("1h30m")
assert.Equal(t, expectedInterval, sp.Delay, "the interval should be parsed correctly")
}
// TestUnmarshalJSON tests the UnmarshalJSON method
func TestUnmarshalJSON(t *testing.T) {
// Example JSON string representing SchedulerPersistence
jsonStr := `{
"time": "2023-12-06T15:04:05Z",
"interval": "1h30m"
}`
// Create an instance of SchedulerPersistence
sp := SchedulerPersistence{}
// Unmarshal the JSON string into the sp structure
err := json.Unmarshal([]byte(jsonStr), &sp)
assert.NoError(t, err, "Unmarshalling should not produce an error")
// Verify that the Time field is correctly parsed
expectedTime, _ := time.Parse(time.RFC3339, "2023-12-06T15:04:05Z")
if sp.Time != nil {
assert.Equal(t, expectedTime, *sp.Time, "Time should be correctly parsed")
} else {
t.Error("Time field is nil, but it should not be")
}
// Verify that the Delay field is correctly parsed
expectedInterval, _ := time.ParseDuration("1h30m")
assert.Equal(t, expectedInterval, sp.Delay, "Interval should be correctly parsed")
}
......@@ -41,7 +41,8 @@ func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error {
// Anonymous structure to avoid endless recursion
type Alias SchedulerPersistence
aux := &struct {
Time *string `json:"time,omitempty"`
Time *string `json:"time,omitempty"`
Interval *string `json:"interval,omitempty"` // Ensure this matches the JSON field name
*Alias
}{
Alias: (*Alias)(sp),
......@@ -66,5 +67,54 @@ func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error {
sp.Time = &t
}
if aux.Interval != nil {
d, err := time.ParseDuration(*aux.Interval)
if err != nil {
return err
}
sp.Delay = d
}
return nil
}
func (sp *SchedulerPersistence) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Anonymous structure to avoid endless recursion
type Alias SchedulerPersistence
aux := &struct {
Time *string `yaml:"time,omitempty"`
Interval *string `yaml:"interval,omitempty"`
*Alias
}{
Alias: (*Alias)(sp),
}
if err := unmarshal(&aux); err != nil {
return err
}
if aux.Time != nil {
var t time.Time
var err error
for _, format := range SupportedTimeFormats {
t, err = time.Parse(format, *aux.Time)
if err == nil {
break
}
}
if err != nil {
return err
}
sp.Time = &t
}
if aux.Interval != nil {
d, err := time.ParseDuration(*aux.Interval)
if err != nil {
return err
}
sp.Delay = d
}
return nil
}