Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Commit

Permalink
Deprecate in favor of github.com/godogx/clocksteps
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm committed Sep 8, 2021
1 parent c4747cf commit d418edb
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 713 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/golangci-lint.yaml

This file was deleted.

60 changes: 0 additions & 60 deletions .github/workflows/test.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
> ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
>
> This module is deprecated. Use `github.com/godogx/clocksteps` instead.
# Cucumber Clock steps for Golang

[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/clockdog)](https://github.com/nhatthm/clockdog/releases/latest)
Expand Down
96 changes: 10 additions & 86 deletions clock.go
Original file line number Diff line number Diff line change
@@ -1,99 +1,23 @@
package clockdog

import (
"errors"
"sync"
"time"

clock "github.com/nhatthm/go-clock"
"github.com/godogx/clocksteps"
)

// ErrClockIsNotSet indicates that the clock must be set by either Clock.Set() or Clock.Freeze() before adding some
// time.Duration into it.
var ErrClockIsNotSet = errors.New("clock is not set")

var _ clock.Clock = (*Clock)(nil)
//
// Deprecated: Use clocksteps.ErrClockIsNotSet instead.
var ErrClockIsNotSet = clocksteps.ErrClockIsNotSet

// Clock is a clock.Clock.
type Clock struct {
timestamp *time.Time
mu sync.Mutex
}

// Now returns a fixed timestamp or time.Now().
func (c *Clock) Now() time.Time {
c.mu.Lock()
defer c.mu.Unlock()

if c.timestamp == nil {
return time.Now()
}

return *c.timestamp
}

// Set fixes the clock at a time.
func (c *Clock) Set(t time.Time) {
c.mu.Lock()
defer c.mu.Unlock()

c.timestamp = timestamp(t)
}

// Add adds time to the clock.
func (c *Clock) Add(d time.Duration) error {
c.mu.Lock()
defer c.mu.Unlock()

if c.timestamp == nil {
return ErrClockIsNotSet
}

c.timestamp = timestamp(c.timestamp.Add(d))

return nil
}

// AddDate adds date to the clock.
func (c *Clock) AddDate(years, months, days int) error {
c.mu.Lock()
defer c.mu.Unlock()

if c.timestamp == nil {
return ErrClockIsNotSet
}

c.timestamp = timestamp(c.timestamp.AddDate(years, months, days))

return nil
}

// Freeze freezes the clock.
func (c *Clock) Freeze() {
c.mu.Lock()
defer c.mu.Unlock()

c.timestamp = timestamp(time.Now())
}

// Unfreeze unfreezes the clock.
func (c *Clock) Unfreeze() {
c.mu.Lock()
defer c.mu.Unlock()

c.timestamp = nil
}

// Clock provides clock.Clock.
func (c *Clock) Clock() clock.Clock {
return c
}
//
// Deprecated: Use clocksteps.Clock instead.
type Clock = clocksteps.Clock

// New initiates a new Clock.
//
// Deprecated: Use clocksteps.New instead.
func New() *Clock {
return &Clock{}
}

func timestamp(t time.Time) *time.Time {
return &t
return clocksteps.New()
}
74 changes: 0 additions & 74 deletions clock_test.go

This file was deleted.

2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// Package clockdog provides a clock for tests with cucumber/godog.
//
// Deprecated: Use github.com/godogx/clocksteps instead.
package clockdog
14 changes: 0 additions & 14 deletions features/background.feature

This file was deleted.

2 changes: 0 additions & 2 deletions features/bootstrap/doc.go

This file was deleted.

Loading

0 comments on commit d418edb

Please sign in to comment.