Skip to content
Snippets Groups Projects
Select Git revision
  • 65a8552f8756202dc940ea8c2315256097b09cc7
  • master default protected
  • v1.16.5
  • v1.16.4
  • v1.16.3
  • v1.16.2
  • v1.16.1
  • v1.16.0
  • v1.15.0
  • v1.14.0
  • v1.13.2
  • v1.13.1
  • v1.13.0
  • v1.12.0
  • v1.11.0
  • v1.10.2
  • v1.10.1
  • v1.10.0
  • v1.9.0
  • v1.8.3
  • v1.8.2
  • v1.8.1
22 results

release.nix

Blame
  • schedule-interval_test.go 1.68 KiB
    // 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.Interval, "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.Interval, "Interval should be correctly parsed")
    }