File: reporter_test.go

package info (click to toggle)
golang-github-protonmail-gluon 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,020 kB
  • sloc: sh: 55; makefile: 5
file content (60 lines) | stat: -rw-r--r-- 1,037 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package tests

import (
	"sync"

	"github.com/ProtonMail/gluon/reporter"
)

type testReporter struct {
	reports []report
	lock    sync.RWMutex
}

type report struct {
	val any
	ctx reporter.Context
}

func (r *testReporter) getReports() []report {
	r.lock.RLock()
	defer r.lock.RUnlock()

	return r.reports
}

func (r *testReporter) ReportException(val any) error {
	r.lock.Lock()
	defer r.lock.Unlock()

	r.reports = append(r.reports, report{val: val})

	return nil
}

func (r *testReporter) ReportMessage(val string) error {
	r.lock.Lock()
	defer r.lock.Unlock()

	r.reports = append(r.reports, report{val: val})

	return nil
}

func (r *testReporter) ReportMessageWithContext(val string, ctx reporter.Context) error {
	r.lock.Lock()
	defer r.lock.Unlock()

	r.reports = append(r.reports, report{val: val, ctx: ctx})

	return nil
}

func (r *testReporter) ReportExceptionWithContext(val any, ctx reporter.Context) error {
	r.lock.Lock()
	defer r.lock.Unlock()

	r.reports = append(r.reports, report{val: val, ctx: ctx})

	return nil
}