github.com/rigado/snapd@v2.42.5-go-mod+incompatible/osutil/outputerr_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package osutil
    21  
    22  import (
    23  	"fmt"
    24  
    25  	. "gopkg.in/check.v1"
    26  )
    27  
    28  type outputErrSuite struct{}
    29  
    30  var _ = Suite(&outputErrSuite{})
    31  
    32  func (ts *outputErrSuite) TestOutputErrOutputWithoutNewlines(c *C) {
    33  	output := "test output"
    34  	err := fmt.Errorf("test error")
    35  	formattedErr := OutputErr([]byte(output), err)
    36  	c.Check(formattedErr, ErrorMatches, output)
    37  }
    38  
    39  func (ts *outputErrSuite) TestOutputErrOutputWithNewlines(c *C) {
    40  	output := "output line1\noutput line2"
    41  	err := fmt.Errorf("test error")
    42  	formattedErr := OutputErr([]byte(output), err)
    43  	c.Check(formattedErr.Error(), Equals, `
    44  -----
    45  output line1
    46  output line2
    47  -----`)
    48  }
    49  
    50  func (ts *outputErrSuite) TestOutputErrNoOutput(c *C) {
    51  	err := fmt.Errorf("test error")
    52  	formattedErr := OutputErr([]byte{}, err)
    53  	c.Check(formattedErr, Equals, err)
    54  }