gopkg.in/ubuntu-core/snappy.v0@v0.0.0-20210902073436-25a8614f10a6/testutil/intcheckers_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2015-2018 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 testutil_test
    21  
    22  import (
    23  	"gopkg.in/check.v1"
    24  
    25  	. "github.com/snapcore/snapd/testutil"
    26  )
    27  
    28  type intCheckersSuite struct{}
    29  
    30  var _ = check.Suite(&intCheckersSuite{})
    31  
    32  func (*intCheckersSuite) TestIntChecker(c *check.C) {
    33  	c.Assert(1, IntLessThan, 2)
    34  	c.Assert(1, IntLessEqual, 1)
    35  	c.Assert(1, IntEqual, 1)
    36  	c.Assert(2, IntNotEqual, 1)
    37  	c.Assert(2, IntGreaterThan, 1)
    38  	c.Assert(2, IntGreaterEqual, 2)
    39  
    40  	// Wrong argument types.
    41  	testCheck(c, IntLessThan, false, "left-hand-side argument must be an int", false, 1)
    42  	testCheck(c, IntLessThan, false, "right-hand-side argument must be an int", 1, false)
    43  
    44  	// Relationship error.
    45  	testCheck(c, IntLessThan, false, "relation 2 < 1 is not true", 2, 1)
    46  	testCheck(c, IntLessEqual, false, "relation 2 <= 1 is not true", 2, 1)
    47  	testCheck(c, IntEqual, false, "relation 2 == 1 is not true", 2, 1)
    48  	testCheck(c, IntNotEqual, false, "relation 2 != 2 is not true", 2, 2)
    49  	testCheck(c, IntGreaterThan, false, "relation 1 > 2 is not true", 1, 2)
    50  	testCheck(c, IntGreaterEqual, false, "relation 1 >= 2 is not true", 1, 2)
    51  
    52  	// Unexpected relation.
    53  	unexpected := UnexpectedIntChecker("===")
    54  	testCheck(c, unexpected, false, `unexpected relation "==="`, 1, 2)
    55  }