github.com/blend/go-sdk@v1.20220411.3/cron/job_invocation_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package cron 9 10 import ( 11 "fmt" 12 "testing" 13 "time" 14 15 "github.com/blend/go-sdk/assert" 16 "github.com/blend/go-sdk/uuid" 17 ) 18 19 func TestJobInvocationElapsed(t *testing.T) { 20 assert := assert.New(t) 21 22 started := time.Now().UTC() 23 24 assert.Equal(200*time.Millisecond, (&JobInvocation{ 25 Started: started, 26 Complete: started.Add(200 * time.Millisecond), 27 }).Elapsed()) 28 29 assert.NotZero((&JobInvocation{ 30 Started: started, 31 }).Elapsed()) 32 } 33 34 func TestJobInvocationClone(t *testing.T) { 35 assert := assert.New(t) 36 37 ts := time.Now().UTC() 38 ji := &JobInvocation{ 39 ID: NewJobInvocationID(), 40 JobName: uuid.V4().String(), 41 Started: ts, 42 Complete: ts.Add(100 * time.Millisecond), 43 Err: fmt.Errorf("this is a test"), 44 Status: JobInvocationStatusErrored, 45 Parameters: map[string]string{"foo": "bar", "example-string": "dog"}, 46 State: "this is also a test", 47 Cancel: func() {}, 48 } 49 cloned := ji.Clone() 50 assert.Equal(ji.ID, cloned.ID) 51 assert.Equal(ji.JobName, cloned.JobName) 52 assert.Equal(ji.Started, cloned.Started) 53 assert.Equal(ji.Complete, cloned.Complete) 54 assert.Equal(ji.Err, cloned.Err) 55 assert.Equal(ji.Status, cloned.Status) 56 assert.Equal(ji.Parameters, cloned.Parameters) 57 assert.Equal(ji.State, cloned.State) 58 assert.NotNil(cloned.Cancel) 59 }