File tree Expand file tree Collapse file tree 2 files changed +58
-47
lines changed
Expand file tree Collapse file tree 2 files changed +58
-47
lines changed Original file line number Diff line number Diff line change 11name : CI
22
33on :
4- push :
5- branches : [ main ]
6- pull_request :
7- branches : [ main ]
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
88
99jobs :
10- test :
11- runs-on : ubuntu-latest
12- steps :
13- - uses : actions/checkout@v3
14- - name : Set up Go
15- uses : actions/setup-go@v4
16- with :
17- go-version : ' 1.21'
18- - name : Test
19- run : |
20- go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
21- - name : Upload coverage
22- uses : codecov/codecov-action@v3
23- with :
24- file : ./coverage.txt
10+ test :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - uses : actions/checkout@v3
14+
15+ - name : Set up Go
16+ uses : actions/setup-go@v4
17+ with :
18+ go-version : ' 1.21'
19+
20+ - name : Check format
21+ run : |
22+ if [ -n "$(gofmt -l .)" ]; then
23+ echo "Files not properly formatted:"
24+ gofmt -l .
25+ exit 1
26+ fi
27+
28+ - name : Test
29+ run : |
30+ go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
31+
32+ - name : Upload coverage
33+ uses : codecov/codecov-action@v3
34+ with :
35+ file : ./coverage.txt
Original file line number Diff line number Diff line change 11package testutil
22
33import (
4- "context"
5- "sync"
4+ "context"
5+ "sync"
66)
77
88// MockSource implements a mock configuration source for testing
99type MockSource [T any ] struct {
10- mu sync.RWMutex
11- current T
12- ch chan T
10+ mu sync.RWMutex
11+ current T
12+ ch chan T
1313}
1414
1515func NewMockSource [T any ]() * MockSource [T ] {
16- return & MockSource [T ]{
17- ch : make (chan T , 1 ),
18- }
16+ return & MockSource [T ]{
17+ ch : make (chan T , 1 ),
18+ }
1919}
2020
2121func (s * MockSource [T ]) Load (ctx context.Context ) (T , error ) {
22- s .mu .RLock ()
23- defer s .mu .RUnlock ()
24- return s .current , nil
22+ s .mu .RLock ()
23+ defer s .mu .RUnlock ()
24+ return s .current , nil
2525}
2626
2727func (s * MockSource [T ]) Watch (ctx context.Context ) (<- chan T , error ) {
28- return s .ch , nil
28+ return s .ch , nil
2929}
3030
3131func (s * MockSource [T ]) Update (value T ) {
32- s .mu .Lock ()
33- s .current = value
34- s .mu .Unlock ()
35-
36- select {
37- case s .ch <- value :
38- default :
39- // Channel is full or closed
40- }
32+ s .mu .Lock ()
33+ s .current = value
34+ s .mu .Unlock ()
35+
36+ select {
37+ case s .ch <- value :
38+ default :
39+ // Channel is full or closed
40+ }
4141}
4242
4343func (s * MockSource [T ]) Close () {
44- close (s .ch )
44+ close (s .ch )
4545}
4646
4747// MockValidator implements a mock validator for testing
4848type MockValidator [T any ] struct {
49- ValidateFunc func (old , new T ) error
49+ ValidateFunc func (old , new T ) error
5050}
5151
5252func (v * MockValidator [T ]) Validate (old , new T ) error {
53- if v .ValidateFunc != nil {
54- return v .ValidateFunc (old , new )
55- }
56- return nil
57- }
53+ if v .ValidateFunc != nil {
54+ return v .ValidateFunc (old , new )
55+ }
56+ return nil
57+ }
You can’t perform that action at this time.
0 commit comments