github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/whitesource/scanPolling_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package whitesource 5 6 import ( 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 "testing" 10 "time" 11 ) 12 13 func TestBlockUntilProjectIsUpdated(t *testing.T) { 14 t.Parallel() 15 16 nowString := "2010-05-30 00:15:00 +0100" 17 now, err := time.Parse(DateTimeLayout, nowString) 18 require.NoError(t, err) 19 options := pollOptions{ 20 scanTime: now, 21 maxAge: 2 * time.Second, 22 timeBetweenPolls: 1 * time.Second, 23 maxWaitTime: 1 * time.Second, 24 } 25 26 t.Run("already new enough", func(t *testing.T) { 27 // init 28 lastUpdatedDate := "2010-05-30 00:15:01 +0100" 29 systemMock := NewSystemMock(lastUpdatedDate) 30 // test 31 err = blockUntilProjectIsUpdated(systemMock.Projects[0].Token, systemMock, options) 32 // assert 33 assert.NoError(t, err) 34 }) 35 t.Run("timeout while polling", func(t *testing.T) { 36 // init 37 lastUpdatedDate := "2010-05-30 00:07:00 +0100" 38 systemMock := NewSystemMock(lastUpdatedDate) 39 // test 40 err = blockUntilProjectIsUpdated(systemMock.Projects[0].Token, systemMock, options) 41 // assert 42 if assert.Error(t, err) { 43 assert.Contains(t, err.Error(), "timeout while waiting") 44 } 45 }) 46 t.Run("timeout while polling, no update time", func(t *testing.T) { 47 // init 48 systemMock := NewSystemMock("") 49 // test 50 err = blockUntilProjectIsUpdated(systemMock.Projects[0].Token, systemMock, options) 51 // assert 52 if assert.Error(t, err) { 53 assert.Contains(t, err.Error(), "timeout while waiting") 54 } 55 }) 56 }