Skip to content

Commit

Permalink
Add test case for internal/errors/observability.go (#993)
Browse files Browse the repository at this point in the history
* feat: add test case and comment for observability errors

Signed-off-by: hlts2 <[email protected]>

* Update internal/errors/observability.go

* Apply suggestions from code review

Co-authored-by: Kiichiro YUKAWA <[email protected]>

* 🤖 Update license headers / Format go codes and yaml files

Signed-off-by: vdaas-ci <[email protected]>

Co-authored-by: Kiichiro YUKAWA <[email protected]>
Co-authored-by: vdaas-ci <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2021
1 parent 5211e87 commit 9394142
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/errors/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
// Package errors provides error types and function
package errors

var ErrCollectorNotFound = func() error {
return New("observability.collector not found")
}
// ErrCollectorNotFound represents a function to generate an error that the observability collector is not found.
var (
ErrCollectorNotFound = func() error {
return New("observability.collector not found")
}
)
72 changes: 72 additions & 0 deletions internal/errors/observability_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Copyright (C) 2019-2021 vdaas.org vald team <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package errors

import (
"testing"

"go.uber.org/goleak"
)

func TestErrCollectorNotFound(t *testing.T) {
t.Parallel()
type want struct {
want error
}
type test struct {
name string
want want
checkFunc func(want, error) error
beforeFunc func()
afterFunc func()
}
defaultCheckFunc := func(w want, got error) error {
if !Is(got, w.want) {
return Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want)
}
return nil
}
tests := []test{
{
name: "return an ErrCollectorNotFound error",
want: want{
want: New("observability.collector not found"),
},
},
}

for _, tc := range tests {
test := tc
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt, goleak.IgnoreCurrent())
if test.beforeFunc != nil {
test.beforeFunc()
}
if test.afterFunc != nil {
defer test.afterFunc()
}
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}

got := ErrCollectorNotFound()
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}
})
}
}

0 comments on commit 9394142

Please sign in to comment.