Merge pull request #850 from harshavardhana/logger-tests

Add tests for minio top level logger
This commit is contained in:
Harshavardhana 2015-09-18 23:44:52 -07:00
commit d808c3685d
5 changed files with 66 additions and 20 deletions

View file

@ -42,8 +42,7 @@ func controllerMain(c *cli.Context) {
if c.Args().Present() {
cli.ShowCommandHelpAndExit(c, "controller", 1)
}
err := controller.Start()
if err != nil {
Fatalln(err)
}
errorIf(err.Trace(), "Failed to start minio controller.", nil)
}

View file

@ -16,8 +16,32 @@
package main
import . "gopkg.in/check.v1"
import (
"bytes"
"encoding/json"
"errors"
func (s *CmdTestSuite) TestLogger(c *C) {
"github.com/Sirupsen/logrus"
"github.com/minio/minio/pkg/probe"
. "gopkg.in/check.v1"
)
func (s *TestSuite) TestLogger(c *C) {
var buffer bytes.Buffer
var fields logrus.Fields
log.Out = &buffer
log.Formatter = new(logrus.JSONFormatter)
errorIf(probe.NewError(errors.New("Fake error")), "Failed with error.", nil)
err := json.Unmarshal(buffer.Bytes(), &fields)
c.Assert(err, IsNil)
c.Assert(fields["level"], Equals, "error")
msg, ok := fields["error"]
c.Assert(ok, Equals, true)
c.Assert(msg, Equals, "Fake error")
_, ok = fields["probe"]
c.Assert(ok, Equals, true)
}

35
minio_test.go Normal file
View file

@ -0,0 +1,35 @@
/*
* Minio Cloud Storage (C) 2015 Minio, Inc.
*
* 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
*
* http://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 main
import (
"testing"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type TestSuite struct{}
var _ = Suite(&TestSuite{})
func (s *TestSuite) SetUpSuite(c *C) {
}
func (s *TestSuite) TearDownSuite(c *C) {
}

View file

@ -17,10 +17,7 @@
package main
import (
"fmt"
"github.com/minio/cli"
"github.com/minio/minio/pkg/probe"
"github.com/minio/minio/pkg/server"
"github.com/minio/minio/pkg/server/api"
)
@ -62,10 +59,8 @@ func serverMain(c *cli.Context) {
if c.Args().Present() {
cli.ShowCommandHelpAndExit(c, "server", 1)
}
apiServerConfig := getServerConfig(c)
err := server.Start(apiServerConfig)
err = probe.NewError(fmt.Errorf("Fake error."))
errorIf(err.Trace(), "Failed to start the server.", nil)
errorIf(err.Trace(), "Failed to start the minio server.", nil)
}

View file

@ -18,19 +18,12 @@ package main
import (
"net/http"
"testing"
"time"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type MySuite struct{}
var _ = Suite(&MySuite{})
func (s *MySuite) TestVersion(c *C) {
func (s *TestSuite) TestVersion(c *C) {
_, err := time.Parse(minioVersion, http.TimeFormat)
c.Assert(err, NotNil)
}