...

Source file src/github.com/doug-martin/goqu/v9/exp/truncate_clauses_test.go

Documentation: github.com/doug-martin/goqu/v9/exp

     1  package exp_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/doug-martin/goqu/v9/exp"
     7  	"github.com/stretchr/testify/suite"
     8  )
     9  
    10  type truncateClausesSuite struct {
    11  	suite.Suite
    12  }
    13  
    14  func TestTruncateClausesSuite(t *testing.T) {
    15  	suite.Run(t, new(truncateClausesSuite))
    16  }
    17  
    18  func (tcs *truncateClausesSuite) TestHasTable() {
    19  	c := exp.NewTruncateClauses()
    20  	cle := exp.NewColumnListExpression("test1", "test2")
    21  	c2 := c.SetTable(cle)
    22  
    23  	tcs.False(c.HasTable())
    24  
    25  	tcs.True(c2.HasTable())
    26  }
    27  
    28  func (tcs *truncateClausesSuite) TestTable() {
    29  	c := exp.NewTruncateClauses()
    30  	cle := exp.NewColumnListExpression("test1", "test2")
    31  	c2 := c.SetTable(cle)
    32  
    33  	tcs.Nil(c.Table())
    34  
    35  	tcs.Equal(cle, c2.Table())
    36  }
    37  
    38  func (tcs *truncateClausesSuite) TestSetTable() {
    39  	cle := exp.NewColumnListExpression("test1", "test2")
    40  	c := exp.NewTruncateClauses().SetTable(cle)
    41  	cle2 := exp.NewColumnListExpression("test3", "test4")
    42  	c2 := c.SetTable(cle2)
    43  
    44  	tcs.Equal(cle, c.Table())
    45  
    46  	tcs.Equal(cle2, c2.Table())
    47  }
    48  
    49  func (tcs *truncateClausesSuite) TestOptions() {
    50  	c := exp.NewTruncateClauses()
    51  	opts := exp.TruncateOptions{Restrict: true, Identity: "RESTART", Cascade: true}
    52  	c2 := c.SetOptions(opts)
    53  
    54  	tcs.Equal(exp.TruncateOptions{}, c.Options())
    55  
    56  	tcs.Equal(opts, c2.Options())
    57  }
    58  
    59  func (tcs *truncateClausesSuite) TestSetOptions() {
    60  	opts := exp.TruncateOptions{Restrict: true, Identity: "RESTART", Cascade: true}
    61  	c := exp.NewTruncateClauses().SetOptions(opts)
    62  	opts2 := exp.TruncateOptions{Restrict: false, Identity: "RESTART", Cascade: false}
    63  	c2 := c.SetOptions(opts2)
    64  
    65  	tcs.Equal(opts, c.Options())
    66  
    67  	tcs.Equal(opts2, c2.Options())
    68  }
    69  

View as plain text