github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/logger/logger_test.go (about)

     1  // Copyright 2015 ThoughtWorks, Inc.
     2  
     3  // This file is part of Gauge.
     4  
     5  // Gauge is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  
    10  // Gauge is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  
    15  // You should have received a copy of the GNU General Public License
    16  // along with Gauge.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package logger
    19  
    20  import (
    21  	"path/filepath"
    22  	"testing"
    23  
    24  	"github.com/getgauge/gauge/config"
    25  	"github.com/op/go-logging"
    26  	. "gopkg.in/check.v1"
    27  )
    28  
    29  func Test(t *testing.T) { TestingT(t) }
    30  
    31  type MySuite struct{}
    32  
    33  var _ = Suite(&MySuite{})
    34  
    35  func (s *MySuite) TestLoggerInitWithInfoLevel(c *C) {
    36  	Initialize("info")
    37  
    38  	c.Assert(GaugeLog.IsEnabledFor(logging.INFO), Equals, true)
    39  	c.Assert(APILog.IsEnabledFor(logging.INFO), Equals, true)
    40  }
    41  
    42  func (s *MySuite) TestLoggerInitWithDefaultLevel(c *C) {
    43  	Initialize("")
    44  
    45  	c.Assert(GaugeLog.IsEnabledFor(logging.INFO), Equals, true)
    46  	c.Assert(APILog.IsEnabledFor(logging.INFO), Equals, true)
    47  }
    48  
    49  func (s *MySuite) TestLoggerInitWithDebugLevel(c *C) {
    50  	Initialize("debug")
    51  
    52  	c.Assert(GaugeLog.IsEnabledFor(logging.DEBUG), Equals, true)
    53  	c.Assert(APILog.IsEnabledFor(logging.DEBUG), Equals, true)
    54  }
    55  
    56  func (s *MySuite) TestLoggerInitWithWarningLevel(c *C) {
    57  	Initialize("warning")
    58  
    59  	c.Assert(GaugeLog.IsEnabledFor(logging.WARNING), Equals, true)
    60  	c.Assert(APILog.IsEnabledFor(logging.WARNING), Equals, true)
    61  }
    62  
    63  func (s *MySuite) TestLoggerInitWithErrorLevel(c *C) {
    64  	Initialize("error")
    65  
    66  	c.Assert(GaugeLog.IsEnabledFor(logging.ERROR), Equals, true)
    67  	c.Assert(APILog.IsEnabledFor(logging.ERROR), Equals, true)
    68  }
    69  
    70  func (s *MySuite) TestGetLogFileGivenRelativePathInGaugeProject(c *C) {
    71  	config.ProjectRoot, _ = filepath.Abs("_testdata")
    72  	expected := filepath.Join(config.ProjectRoot, apiLogFileName)
    73  
    74  	c.Assert(getLogFile(apiLogFileName), Equals, expected)
    75  }
    76  
    77  func (s *MySuite) TestGetLogFileInGaugeProject(c *C) {
    78  	config.ProjectRoot, _ = filepath.Abs("_testdata")
    79  	expected := filepath.Join(config.ProjectRoot, apiLogFileName)
    80  
    81  	c.Assert(getLogFile(filepath.Join(config.ProjectRoot, apiLogFileName)), Equals, expected)
    82  }
    83  
    84  func (s *MySuite) TestGetLogFileInGaugeProjectGivenAbsPath(c *C) {
    85  	config.ProjectRoot, _ = filepath.Abs("_testdata")
    86  	customLogsDir := filepath.Join(config.ProjectRoot, "myLogsDir")
    87  
    88  	logFile := getLogFile(filepath.Join(customLogsDir, apiLogFileName))
    89  
    90  	c.Assert(logFile, Equals, filepath.Join(customLogsDir, apiLogFileName))
    91  }