Skip to content

Commit

Permalink
feat: add validate
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-shin0 committed Apr 25, 2024
1 parent b312c2c commit 37c02f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autopprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ func TestAutoPprof_watchGoroutineCount_consecutive(t *testing.T) {
GoroutineCount().
AnyTimes().
DoAndReturn(
func() (float64, error) {
func() (int, error) {
return 200, nil
},
)
Expand Down
3 changes: 3 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var (
ErrInvalidMemThreshold = fmt.Errorf(
"autopprof: memory threshold value must be between 0 and 1",
)
ErrInvalidGoroutineThreshold = fmt.Errorf(
"autopprof: goroutine threshold value must be greater than 0",
)
ErrNilReporter = fmt.Errorf("autopprof: Reporter can't be nil")
ErrDisableAllProfiling = fmt.Errorf("autopprof: all profiling is disabled")
)
5 changes: 4 additions & 1 deletion option.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Option struct {

// NOTE(mingrammer): testing the validate() is done in autopprof_test.go.
func (o Option) validate() error {
if o.DisableCPUProf && o.DisableMemProf {
if o.DisableCPUProf && o.DisableMemProf && o.DisableGoroutineProf {
return ErrDisableAllProfiling
}
if o.CPUThreshold < 0 || o.CPUThreshold > 1 {
Expand All @@ -62,6 +62,9 @@ func (o Option) validate() error {
if o.MemThreshold < 0 || o.MemThreshold > 1 {
return ErrInvalidMemThreshold
}
if o.GoroutineThreshold <= 0 {
return ErrInvalidGoroutineThreshold
}
if o.Reporter == nil {
return ErrNilReporter
}
Expand Down

0 comments on commit 37c02f3

Please sign in to comment.