From 7d8cfa0a77cd65ad3f32e0fe2fd25d6bc94f7763 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 18 Sep 2015 23:32:31 -0700 Subject: [PATCH] Add tests for minio top level --- controller-main.go | 5 ++--- logger_test.go | 28 ++++++++++++++++++++++++++-- minio_test.go | 35 +++++++++++++++++++++++++++++++++++ server-main.go | 9 ++------- version_test.go | 9 +-------- 5 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 minio_test.go diff --git a/controller-main.go b/controller-main.go index 52bf4b9f0..ee2fad55c 100644 --- a/controller-main.go +++ b/controller-main.go @@ -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) } diff --git a/logger_test.go b/logger_test.go index 576d05949..36600ec89 100644 --- a/logger_test.go +++ b/logger_test.go @@ -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) } diff --git a/minio_test.go b/minio_test.go new file mode 100644 index 000000000..11fdcf121 --- /dev/null +++ b/minio_test.go @@ -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) { +} diff --git a/server-main.go b/server-main.go index 1e5ce8d65..da7150192 100644 --- a/server-main.go +++ b/server-main.go @@ -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) + 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) } diff --git a/version_test.go b/version_test.go index 86fc81b56..bf467b3d6 100644 --- a/version_test.go +++ b/version_test.go @@ -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) }