File: mock_time.go

package info (click to toggle)
golang-github-pion-interceptor 0.1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 764 kB
  • sloc: makefile: 8
file content (26 lines) | stat: -rw-r--r-- 421 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package test

import (
	"sync"
	"time"
)

// MockTime is a helper to replace time.Now() for testing purposes.
type MockTime struct {
	m      sync.RWMutex
	curNow time.Time
}

// SetNow sets the current time.
func (t *MockTime) SetNow(n time.Time) {
	t.m.Lock()
	defer t.m.Unlock()
	t.curNow = n
}

// Now returns the current time.
func (t *MockTime) Now() time.Time {
	t.m.RLock()
	defer t.m.RUnlock()
	return t.curNow
}