gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/utility_test.go (about)

     1  package ign
     2  
     3  import (
     4  	"errors"
     5  	"github.com/stretchr/testify/assert"
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  // Tests for utility file
    11  
    12  // TestStrToSlice tests the StrToSlice func
    13  func TestStrToSlice(t *testing.T) {
    14  
    15  	type exp struct {
    16  		input string
    17  		exp   []string
    18  	}
    19  	var inputs = []exp{
    20  		{" tag middle space,  test_tag2 ,   , test_tag_1,  ",
    21  			[]string{"tag middle space", "test_tag_1", "test_tag2"},
    22  		},
    23  	}
    24  
    25  	for _, i := range inputs {
    26  		got := StrToSlice(i.input)
    27  		for _, s := range got {
    28  			t.Log("got:", strings.Replace(s, " ", "%s", -1))
    29  		}
    30  		assert.True(t, SameElements(i.exp, got), "Didn't get expected string slice exp:[%s] got:[%s]", i.exp, got)
    31  	}
    32  }
    33  
    34  func TestIsError(t *testing.T) {
    35  	target := errors.New("test")
    36  	err := errors.New("this is a test error")
    37  	assert.True(t, IsError(err, target))
    38  
    39  	err = errors.New("another error")
    40  	assert.False(t, IsError(err, target))
    41  }