-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test for internal/errors/compressor.go #870
Changes from all commits
153e476
16321f4
5fc9571
1b18d79
7238074
a90269a
d602bf2
a9c4f8e
c057c09
9aa3013
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,29 +18,35 @@ | |
package errors | ||
|
||
var ( | ||
// internal compressor | ||
// ErrInvalidCompressionLevel represents a function to generate an error of invalid compression level. | ||
ErrInvalidCompressionLevel = func(level int) error { | ||
return Errorf("invalid compression level: %d", level) | ||
} | ||
|
||
// Compressor | ||
// ErrCompressorNameNotFound represents a function to generate an error of compressor not found. | ||
ErrCompressorNameNotFound = func(name string) error { | ||
return Errorf("compressor %s not found", name) | ||
} | ||
|
||
// ErrCompressedDataNotFound returns an error of compressed data is not found. | ||
ErrCompressedDataNotFound = New("compressed data not found") | ||
|
||
// ErrDecompressedDataNotFound returns an error of decompressed data is not found. | ||
ErrDecompressedDataNotFound = New("decompressed data not found") | ||
|
||
// ErrCompressFailed returns an error of compress failed. | ||
ErrCompressFailed = New("compress failed") | ||
|
||
// ErrDecompressFailed returns an error of decompressing failed. | ||
ErrDecompressFailed = New("decompress failed") | ||
|
||
// ErrCompressorRegistererIsNotRunning represents a function to generate an error of compressor registerers is not running. | ||
ErrCompressorRegistererIsNotRunning = func() error { | ||
return Errorf("compressor registerers is not running") | ||
return New("compressor registerers is not running") | ||
} | ||
|
||
// ErrCompressorRegistererChannelIsFull represents a function to generate an error that compressor registerer channel is full. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
ErrCompressorRegistererChannelIsFull = func() error { | ||
return Errorf("compressor registerer channel is full") | ||
return New("compressor registerer channel is full") | ||
} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
// | ||
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt ) | ||
// | ||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [golangci] reported by reviewdog 🐶 |
||
|
||
import ( | ||
"math" | ||
"testing" | ||
) | ||
|
||
func TestErrInvalidCompressionLevel(t *testing.T) { | ||
type args struct { | ||
level int | ||
} | ||
type want struct { | ||
want error | ||
} | ||
type test struct { | ||
name string | ||
args args | ||
want want | ||
checkFunc func(want, error) error | ||
beforeFunc func(args) | ||
afterFunc func(args) | ||
} | ||
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: "returns error when compression leve is 100", | ||
args: args{ | ||
level: 100, | ||
}, | ||
want: want{ | ||
want: New("invalid compression level: 100"), | ||
}, | ||
}, | ||
{ | ||
name: "returns error when compression leve is 0", | ||
args: args{ | ||
level: 0, | ||
hlts2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
want: want{ | ||
want: New("invalid compression level: 0"), | ||
}, | ||
}, | ||
{ | ||
name: "returns error when compression leve is the maximum number of int", | ||
args: args{ | ||
level: int(math.MaxInt64), | ||
}, | ||
want: want{ | ||
want: Errorf("invalid compression level: %d", int(math.MaxInt64)), | ||
}, | ||
}, | ||
{ | ||
name: "returns error when compression leve is the minimum number of int", | ||
args: args{ | ||
level: int(math.MinInt64), | ||
}, | ||
want: want{ | ||
want: Errorf("invalid compression level: %d", int(math.MinInt64)), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
if test.beforeFunc != nil { | ||
test.beforeFunc(test.args) | ||
} | ||
if test.afterFunc != nil { | ||
defer test.afterFunc(test.args) | ||
} | ||
if test.checkFunc == nil { | ||
test.checkFunc = defaultCheckFunc | ||
} | ||
|
||
got := ErrInvalidCompressionLevel(test.args.level) | ||
if err := test.checkFunc(test.want, got); err != nil { | ||
tt.Errorf("error = %v", err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestErrCompressorNameNotFound(t *testing.T) { | ||
type args struct { | ||
name string | ||
} | ||
type want struct { | ||
want error | ||
} | ||
type test struct { | ||
name string | ||
args args | ||
want want | ||
checkFunc func(want, error) error | ||
beforeFunc func(args) | ||
afterFunc func(args) | ||
} | ||
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: "returns error when name is `gob`", | ||
args: args{ | ||
name: "gob", | ||
}, | ||
want: want{ | ||
want: New("compressor gob not found"), | ||
}, | ||
}, | ||
{ | ||
name: "returns error when name is empty", | ||
args: args{ | ||
name: "", | ||
}, | ||
want: want{ | ||
want: New("compressor not found"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
if test.beforeFunc != nil { | ||
test.beforeFunc(test.args) | ||
} | ||
if test.afterFunc != nil { | ||
defer test.afterFunc(test.args) | ||
} | ||
if test.checkFunc == nil { | ||
test.checkFunc = defaultCheckFunc | ||
} | ||
|
||
got := ErrCompressorNameNotFound(test.args.name) | ||
if err := test.checkFunc(test.want, got); err != nil { | ||
tt.Errorf("error = %v", err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestErrCompressorRegistererIsNotRunning(t *testing.T) { | ||
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: "returns error", | ||
want: want{ | ||
want: New("compressor registerers is not running"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
if test.beforeFunc != nil { | ||
test.beforeFunc() | ||
} | ||
if test.afterFunc != nil { | ||
defer test.afterFunc() | ||
} | ||
if test.checkFunc == nil { | ||
test.checkFunc = defaultCheckFunc | ||
} | ||
|
||
got := ErrCompressorRegistererIsNotRunning() | ||
if err := test.checkFunc(test.want, got); err != nil { | ||
tt.Errorf("error = %v", err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestErrCompressorRegistererChannelIsFull(t *testing.T) { | ||
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: "returns error", | ||
want: want{ | ||
want: New("compressor registerer channel is full"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(tt *testing.T) { | ||
if test.beforeFunc != nil { | ||
test.beforeFunc() | ||
} | ||
if test.afterFunc != nil { | ||
defer test.afterFunc() | ||
} | ||
if test.checkFunc == nil { | ||
test.checkFunc = defaultCheckFunc | ||
} | ||
|
||
got := ErrCompressorRegistererChannelIsFull() | ||
if err := test.checkFunc(test.want, got); err != nil { | ||
tt.Errorf("error = %v", err) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golangci] reported by reviewdog 🐶
line is 124 characters (lll)