From a4de85dc806f6b7e344eb5bf8424ef2bb4815571 Mon Sep 17 00:00:00 2001 From: ᴜɴᴋɴᴡᴏɴ Date: Mon, 16 Mar 2020 01:54:08 +0800 Subject: util: add tests (#5989) --- internal/errutil/errutil_test.go | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/errutil/errutil_test.go (limited to 'internal/errutil') diff --git a/internal/errutil/errutil_test.go b/internal/errutil/errutil_test.go new file mode 100644 index 00000000..9fcffbc0 --- /dev/null +++ b/internal/errutil/errutil_test.go @@ -0,0 +1,53 @@ +// Copyright 2020 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package errutil + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" +) + +type notFoundError struct { + val bool +} + +func (notFoundError) Error() string { + return "not found" +} + +func (e notFoundError) NotFound() bool { + return e.val +} + +func TestIsNotFound(t *testing.T) { + tests := []struct { + name string + err error + expVal bool + }{ + { + name: "error does not implement NotFound", + err: errors.New("a simple error"), + expVal: false, + }, + { + name: "error implements NotFound but not a not found", + err: notFoundError{val: false}, + expVal: false, + }, + { + name: "error implements NotFound", + err: notFoundError{val: true}, + expVal: true, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + assert.Equal(t, test.expVal, IsNotFound(test.err)) + }) + } +} -- cgit v1.2.3