Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use own FakeClock func instead of from library
Browse files Browse the repository at this point in the history
We were using clockwork.NewFakeClock() from the clockwork library. With
recent changes the implementation of this function changed and it now
returns the current date instead of an older date.

Creating the function FakeClock() in `pkg/test/helpers.go` so that we
can manually hardcode the date and not 100% rely on the library.

Signed-off-by: vinamra28 <[email protected]>
vinamra28 committed Apr 14, 2023
1 parent 77cf380 commit ccd3868
Showing 12 changed files with 40 additions and 34 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ $(BIN)/golangci-lint: ; $(info $(M) getting golangci-lint $(GOLANGCI_VERSION))
.PHONY: lint-go
lint-go: | $(GOLANGCILINT) ; $(info $(M) running golangci-lint…) @ ## Run golangci-lint
$Q $(GOLANGCILINT) run --modules-download-mode=vendor --max-issues-per-linter=0 --max-same-issues=0 --deadline 5m
@rm -f $(GOLANGCILINT)

GOIMPORTS = $(BIN)/goimports
$(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports
2 changes: 1 addition & 1 deletion pkg/cmd/pipeline/list_test.go
Original file line number Diff line number Diff line change
@@ -1094,7 +1094,7 @@ func TestPipelinesList_latest_run(t *testing.T) {

func TestPipelineList_in_all_namespaces_with_output_yaml_flag(t *testing.T) {

clock := clockwork.NewFakeClock()
clock := test.FakeClock()
version := "v1"

pdata := []*v1.Pipeline{
5 changes: 2 additions & 3 deletions pkg/cmd/pipelinerun/delete_test.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ import (
"testing"
"time"

"github.com/jonboulle/clockwork"
"github.com/tektoncd/cli/pkg/test"
cb "github.com/tektoncd/cli/pkg/test/builder"
testDynamic "github.com/tektoncd/cli/pkg/test/dynamic"
@@ -36,7 +35,7 @@ import (
func TestPipelineRunDelete_v1beta1(t *testing.T) {

version := "v1beta1"
clock := clockwork.NewFakeClock()
clock := test.FakeClock()

ns := []*corev1.Namespace{
{
@@ -659,7 +658,7 @@ func TestPipelineRunDelete_v1beta1(t *testing.T) {

func TestPipelineRunDelete(t *testing.T) {
version := "v1"
clock := clockwork.NewFakeClock()
clock := test.FakeClock()

ns := []*corev1.Namespace{
{
14 changes: 7 additions & 7 deletions pkg/cmd/pipelinerun/describe_test.go
Original file line number Diff line number Diff line change
@@ -1351,7 +1351,7 @@ func TestPipelineRunDescribe_custom_output_v1beta1(t *testing.T) {
}

func TestPipelineRunDescribe_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1beta1.TaskRun{
{
@@ -1514,7 +1514,7 @@ func TestPipelineRunDescribe_v1beta1(t *testing.T) {
}

func TestPipelineRunDescribe_taskrun_with_no_status_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1beta1.TaskRun{
{
@@ -1663,7 +1663,7 @@ func TestPipelineRunDescribe_taskrun_with_no_status_v1beta1(t *testing.T) {
}

func TestPipelineRunDescribe_last_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname1 := "pipeline-run"
pipelinerunname2 := "pipeline-run2"
taskRuns := []*v1beta1.TaskRun{
@@ -1900,7 +1900,7 @@ func TestPipelineRunDescribe_last_v1beta1(t *testing.T) {
}

func TestPipelineRunDescribe_with_results_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1beta1.TaskRun{
{
@@ -2080,7 +2080,7 @@ func TestPipelineRunDescribe_zero_timeout_v1beta1(t *testing.T) {
}

func TestPipelineRunDescribe_with_workspaces_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1beta1.TaskRun{
{
@@ -2232,7 +2232,7 @@ func TestPipelineRunDescribe_with_workspaces_v1beta1(t *testing.T) {
}

func TestPipelineRunDescribeWithSkippedTasks_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1beta1.TaskRun{
{
@@ -2558,7 +2558,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun_v1beta1(t *t
}

func TestPipelineRunDescribeWithTimeouts_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1beta1.TaskRun{
{
14 changes: 7 additions & 7 deletions pkg/cmd/pipelinerun/describe_v1_test.go
Original file line number Diff line number Diff line change
@@ -1390,7 +1390,7 @@ func TestPipelineRunDescribe_custom_output(t *testing.T) {
}

func TestPipelineRunDescribe(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1.TaskRun{
{
@@ -1539,7 +1539,7 @@ func TestPipelineRunDescribe(t *testing.T) {
}

func TestPipelineRunDescribe_taskrun_with_no_status(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1.TaskRun{
{
@@ -1674,7 +1674,7 @@ func TestPipelineRunDescribe_taskrun_with_no_status(t *testing.T) {
}

func TestPipelineRunDescribe_last(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname1 := "pipeline-run"
pipelinerunname2 := "pipeline-run2"
taskRuns := []*v1.TaskRun{
@@ -1883,7 +1883,7 @@ func TestPipelineRunDescribe_last(t *testing.T) {
}

func TestPipelineRunDescribe_with_results(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1.TaskRun{
{
@@ -2055,7 +2055,7 @@ func TestPipelineRunDescribe_zero_timeout(t *testing.T) {
}

func TestPipelineRunDescribe_with_workspaces(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1.TaskRun{
{
@@ -2199,7 +2199,7 @@ func TestPipelineRunDescribe_with_workspaces(t *testing.T) {
}

func TestPipelineRunDescribeWithSkippedTasks(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1.TaskRun{
{
@@ -2513,7 +2513,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun(t *testing.T
}

func TestPipelineRunDescribeWithTimeouts(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pipelinerunname := "pipeline-run"
taskRuns := []*v1.TaskRun{
{
2 changes: 1 addition & 1 deletion pkg/cmd/task/list_test.go
Original file line number Diff line number Diff line change
@@ -1058,7 +1058,7 @@ func TestTaskList_Only_Tasks_all_namespaces_no_headers(t *testing.T) {
}

func TestTaskList_in_all_namespaces_with_output_yaml_flag(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()

tasks := []*v1.Task{
{
4 changes: 2 additions & 2 deletions pkg/cmd/taskrun/delete_test.go
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ import (
)

func TestTaskRunDelete_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()

ns := []*corev1.Namespace{
{
@@ -893,7 +893,7 @@ func TestTaskRunDelete_v1beta1(t *testing.T) {
}

func TestTaskRunDelete(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()

ns := []*corev1.Namespace{
{
16 changes: 8 additions & 8 deletions pkg/cmd/taskrun/describe_test.go
Original file line number Diff line number Diff line change
@@ -1122,7 +1122,7 @@ func TestTaskRunDescribe_WithSpec_custom_timeout_v1beta1(t *testing.T) {
}

func TestTaskRunDescribe_last_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1beta1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
@@ -1207,7 +1207,7 @@ func TestTaskRunDescribe_last_v1beta1(t *testing.T) {
}

func TestTaskRunDescribe_With_Results_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1beta1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
@@ -1325,7 +1325,7 @@ func TestTaskRunDescribe_zero_timeout_v1beta1(t *testing.T) {
}

func TestTaskRunDescribe_With_Workspaces_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1beta1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
@@ -1420,7 +1420,7 @@ func TestTaskRunDescribe_With_Workspaces_v1beta1(t *testing.T) {
}

func TestTaskRunDescribe_WithoutNameIfOnlyOneTaskRunPresent_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1beta1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
@@ -2395,7 +2395,7 @@ func TestTaskRunDescribe_WithSpec_custom_timeout(t *testing.T) {
}

func TestTaskRunDescribe_last(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
@@ -2480,7 +2480,7 @@ func TestTaskRunDescribe_last(t *testing.T) {
}

func TestTaskRunDescribe_With_Results(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
@@ -2598,7 +2598,7 @@ func TestTaskRunDescribe_zero_timeout(t *testing.T) {
}

func TestTaskRunDescribe_With_Workspaces(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
@@ -2693,7 +2693,7 @@ func TestTaskRunDescribe_With_Workspaces(t *testing.T) {
}

func TestTaskRunDescribe_WithoutNameIfOnlyOneTaskRunPresent(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
taskRuns := []*v1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
4 changes: 2 additions & 2 deletions pkg/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ import (

func TestPipelineRunsList_v1beta1(t *testing.T) {
version := "v1beta1"
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pr1Started := clock.Now().Add(10 * time.Second)
runDuration := 1 * time.Minute
prdata := []*v1beta1.PipelineRun{
@@ -199,7 +199,7 @@ func TestPipelineRunsList_v1beta1(t *testing.T) {

func TestPipelineRunsList(t *testing.T) {
version := "v1"
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
pr1Started := clock.Now().Add(10 * time.Second)
runDuration := 1 * time.Minute
prdata := []*v1.PipelineRun{
4 changes: 2 additions & 2 deletions pkg/taskrun/list_test.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ import (
)

func TestPipelinesList_GetAllTaskRuns_v1beta1(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
trStarted := clock.Now().Add(10 * time.Second)
runDuration1 := 1 * time.Minute
runDuration2 := 1 * time.Minute
@@ -169,7 +169,7 @@ func TestPipelinesList_GetAllTaskRuns_v1beta1(t *testing.T) {
}

func TestPipelinesList_GetAllTaskRuns(t *testing.T) {
clock := clockwork.NewFakeClock()
clock := test.FakeClock()
trStarted := clock.Now().Add(10 * time.Second)
runDuration1 := 1 * time.Minute
runDuration2 := 1 * time.Minute
6 changes: 6 additions & 0 deletions pkg/test/helpers.go
Original file line number Diff line number Diff line change
@@ -18,8 +18,10 @@ import (
"reflect"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/jonboulle/clockwork"
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
pipelinetest "github.com/tektoncd/pipeline/test"
triggerstest "github.com/tektoncd/triggers/test"
@@ -92,3 +94,7 @@ func Contains(t *testing.T, container interface{}, obj interface{}) {
}
t.Errorf("no matches found in: %s", strings.Join(diffs, "\n"))
}

func FakeClock() clockwork.FakeClock {
return clockwork.NewFakeClockAt(time.Date(1984, time.April, 4, 0, 0, 0, 0, time.UTC))
}
2 changes: 1 addition & 1 deletion pkg/test/params.go
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ func (p *Params) Clients(config ...*rest.Config) (*cli.Clients, error) {

func (p *Params) Time() clockwork.Clock {
if p.Clock == nil {
p.Clock = clockwork.NewFakeClock()
p.Clock = FakeClock()
}
return p.Clock
}

0 comments on commit ccd3868

Please sign in to comment.