Commit 75f83640
75f83640ff77Merged
Svyatoslav Dumchenko <[email protected]> ยท 5 years ago ยท 2 files ยท +2 added
Description
add helper tests
Details
- Commit
- 75f83640ff77
- Parent
- 6fab40d47f22
pkg/helper/func_test.goaddedView file
1+
package helper2+
3+
import (4+
"github.com/stretchr/testify/suite"5+
"os"6+
"path"7+
"sort"8+
"strconv"9+
"syscall"10+
"testing"11+
"time"12+
)13+
14+
type HelperTestSuite struct {15+
suite.Suite16+
}17+
18+
func (s *HelperTestSuite) TestContains() {19+
tests := []struct {20+
t string21+
a []string22+
out bool23+
}{24+
{25+
t: "",26+
a: []string{},27+
out: false,28+
},29+
{30+
t: "123",31+
a: []string{},32+
out: false,33+
},34+
{35+
t: "321",36+
a: []string{"123", "321"},37+
out: true,38+
},39+
}40+
41+
for _, t := range tests {42+
sort.Strings(t.a)43+
s.Equalf(t.out, Contains(t.t, t.a), "checking %v in %v", t.t, t.a)44+
}45+
}46+
47+
func (s *HelperTestSuite) TestCreateFile() {48+
tmpPath := path.Join(os.TempDir(), strconv.Itoa(time.Now().Second()))49+
defer func(name string) {50+
_ = os.Remove(name)51+
}(tmpPath)52+
53+
f, err := CreateFile(tmpPath)54+
55+
s.Require().FileExists(tmpPath)56+
s.Require().NoError(err)57+
s.Require().NotNil(f)58+
59+
err = f.Close()60+
s.Require().NoError(err)61+
62+
tmpPath = path.Join(tmpPath, "123")63+
_, err = CreateFile(tmpPath)64+
65+
s.Error(err)66+
s.IsType(&os.PathError{}, err)67+
s.Equal(syscall.ENOTDIR, err.(*os.PathError).Err)68+
}69+
70+
func TestHelperTestSuite(t *testing.T) {71+
t.Parallel()72+
suite.Run(t, new(HelperTestSuite))73+
}pkg/helper/helm_test.goaddedView file
Loading diffโฆ