diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2021-10-11 09:27:39 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2022-06-12 16:49:49 -0700 |
| commit | 85dc7715f497e8c06cfec8e8597ef5b15b2374ff (patch) | |
| tree | 2c8c5e0db9de680111c44da52942396590605eb7 | |
| parent | de0eb9dd4443ff2f852e40ce518e2e8ef537a5f1 (diff) | |
Parallelizing more tests
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
| -rw-r--r-- | crypto/pbkdf2_test.go | 4 | ||||
| -rw-r--r-- | crypto/rsa_test.go | 72 | ||||
| -rw-r--r-- | funcs/aws_test.go | 4 | ||||
| -rw-r--r-- | funcs/base64_test.go | 10 | ||||
| -rw-r--r-- | funcs/coll_test.go | 8 | ||||
| -rw-r--r-- | funcs/conv_test.go | 6 | ||||
| -rw-r--r-- | funcs/crypto_test.go | 51 | ||||
| -rw-r--r-- | funcs/data_test.go | 2 | ||||
| -rw-r--r-- | funcs/env_test.go | 4 | ||||
| -rw-r--r-- | funcs/file_test.go | 8 | ||||
| -rw-r--r-- | funcs/filepath_test.go | 2 | ||||
| -rw-r--r-- | funcs/filepath_unix_test.go | 2 | ||||
| -rw-r--r-- | funcs/filepath_windows_test.go | 2 | ||||
| -rw-r--r-- | funcs/gcp_test.go | 2 | ||||
| -rw-r--r-- | funcs/math_test.go | 48 | ||||
| -rw-r--r-- | funcs/net_test.go | 10 | ||||
| -rw-r--r-- | funcs/path_test.go | 4 | ||||
| -rw-r--r-- | funcs/random_test.go | 18 | ||||
| -rw-r--r-- | funcs/regexp_test.go | 14 | ||||
| -rw-r--r-- | funcs/sockaddr_test.go | 2 | ||||
| -rw-r--r-- | funcs/strings_test.go | 22 | ||||
| -rw-r--r-- | funcs/test_test.go | 12 | ||||
| -rw-r--r-- | funcs/time_test.go | 4 | ||||
| -rw-r--r-- | funcs/uuid_test.go | 12 | ||||
| -rw-r--r-- | internal/tests/integration/plugins_test.go | 21 |
25 files changed, 302 insertions, 42 deletions
diff --git a/crypto/pbkdf2_test.go b/crypto/pbkdf2_test.go index 7d46159f..327ee322 100644 --- a/crypto/pbkdf2_test.go +++ b/crypto/pbkdf2_test.go @@ -8,6 +8,8 @@ import ( ) func TestPBKDF2(t *testing.T) { + t.Parallel() + dk, err := PBKDF2([]byte{}, []byte{}, 0, 0, 0) assert.Nil(t, dk) assert.Error(t, err) @@ -56,6 +58,8 @@ func TestPBKDF2(t *testing.T) { } func TestStrToHash(t *testing.T) { + t.Parallel() + h, err := StrToHash("foo") assert.Zero(t, h) assert.Error(t, err) diff --git a/crypto/rsa_test.go b/crypto/rsa_test.go index 8a7c2dde..42297f2c 100644 --- a/crypto/rsa_test.go +++ b/crypto/rsa_test.go @@ -49,38 +49,62 @@ func derivePKCS1PubKey(priv *rsa.PrivateKey) string { } func TestRSACrypt(t *testing.T) { + t.Parallel() + priv, testPrivKey := genPKCS1PrivKey() - testPubKey := derivePKIXPubKey(priv) - in := []byte("hello world") - key := "bad key" - _, err := RSAEncrypt(key, in) - assert.Error(t, err) + testdata := []struct { + name string + encKey string + decKey string + in []byte + }{ + {"pkix key", derivePKIXPubKey(priv), testPrivKey, []byte("hello world")}, + {"pkcs1 key", derivePKCS1PubKey(priv), testPrivKey, []byte("hello world")}, + } - _, err = RSADecrypt(key, in) - assert.Error(t, err) + for _, d := range testdata { + d := d + t.Run(d.name, func(t *testing.T) { + t.Parallel() - key = "" - _, err = RSAEncrypt(key, in) - assert.Error(t, err) - _, err = RSADecrypt(key, in) - assert.Error(t, err) + enc, err := RSAEncrypt(d.encKey, d.in) + assert.NoError(t, err) - enc, err := RSAEncrypt(testPubKey, in) - assert.NoError(t, err) - dec, err := RSADecrypt(testPrivKey, enc) - assert.NoError(t, err) - assert.Equal(t, in, dec) + dec, err := RSADecrypt(d.decKey, enc) + assert.NoError(t, err) + assert.Equal(t, d.in, dec) + }) + } - testPubKey = derivePKCS1PubKey(priv) - enc, err = RSAEncrypt(testPubKey, in) - assert.NoError(t, err) - dec, err = RSADecrypt(testPrivKey, enc) - assert.NoError(t, err) - assert.Equal(t, in, dec) + t.Run("bad key", func(t *testing.T) { + t.Parallel() + + in := []byte("hello world") + key := "bad key" + _, err := RSAEncrypt(key, in) + assert.Error(t, err) + + _, err = RSADecrypt(key, in) + assert.Error(t, err) + }) + + t.Run("empty key", func(t *testing.T) { + t.Parallel() + + in := []byte("hello world") + key := "" + _, err := RSAEncrypt(key, in) + assert.Error(t, err) + + _, err = RSADecrypt(key, in) + assert.Error(t, err) + }) } func TestRSAGenerateKey(t *testing.T) { + t.Parallel() + _, err := RSAGenerateKey(0) assert.Error(t, err) @@ -96,6 +120,8 @@ func TestRSAGenerateKey(t *testing.T) { } func TestRSADerivePublicKey(t *testing.T) { + t.Parallel() + _, err := RSADerivePublicKey(nil) assert.Error(t, err) diff --git a/funcs/aws_test.go b/funcs/aws_test.go index 79324f70..2bfdf3d5 100644 --- a/funcs/aws_test.go +++ b/funcs/aws_test.go @@ -10,6 +10,8 @@ import ( ) func TestCreateAWSFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -25,6 +27,8 @@ func TestCreateAWSFuncs(t *testing.T) { } func TestAWSFuncs(t *testing.T) { + t.Parallel() + m := aws.NewDummyEc2Meta() i := aws.NewDummyEc2Info(m) af := &Funcs{meta: m, info: i} diff --git a/funcs/base64_test.go b/funcs/base64_test.go index 4c611fee..54cd993b 100644 --- a/funcs/base64_test.go +++ b/funcs/base64_test.go @@ -10,6 +10,8 @@ import ( ) func TestCreateBase64Funcs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -25,16 +27,22 @@ func TestCreateBase64Funcs(t *testing.T) { } func TestBase64Encode(t *testing.T) { + t.Parallel() + bf := &Base64Funcs{} assert.Equal(t, "Zm9vYmFy", must(bf.Encode("foobar"))) } func TestBase64Decode(t *testing.T) { + t.Parallel() + bf := &Base64Funcs{} assert.Equal(t, "foobar", must(bf.Decode("Zm9vYmFy"))) } func TestBase64DecodeBytes(t *testing.T) { + t.Parallel() + bf := &Base64Funcs{} out, err := bf.DecodeBytes("Zm9vYmFy") assert.NoError(t, err) @@ -42,6 +50,8 @@ func TestBase64DecodeBytes(t *testing.T) { } func TestToBytes(t *testing.T) { + t.Parallel() + assert.Equal(t, []byte{0, 1, 2, 3}, toBytes([]byte{0, 1, 2, 3})) buf := &bytes.Buffer{} diff --git a/funcs/coll_test.go b/funcs/coll_test.go index 44dcced4..9b6a0b9a 100644 --- a/funcs/coll_test.go +++ b/funcs/coll_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateCollFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -24,6 +26,8 @@ func TestCreateCollFuncs(t *testing.T) { } func TestFlatten(t *testing.T) { + t.Parallel() + c := CollFuncs{} _, err := c.Flatten() @@ -42,6 +46,8 @@ func TestFlatten(t *testing.T) { } func TestPick(t *testing.T) { + t.Parallel() + c := &CollFuncs{} _, err := c.Pick() @@ -89,6 +95,8 @@ func TestPick(t *testing.T) { } func TestOmit(t *testing.T) { + t.Parallel() + c := &CollFuncs{} _, err := c.Omit() diff --git a/funcs/conv_test.go b/funcs/conv_test.go index b9aa757e..3e25c6d0 100644 --- a/funcs/conv_test.go +++ b/funcs/conv_test.go @@ -10,6 +10,8 @@ import ( ) func TestCreateConvFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -25,6 +27,8 @@ func TestCreateConvFuncs(t *testing.T) { } func TestDefault(t *testing.T) { + t.Parallel() + s := struct{}{} c := &ConvFuncs{} def := "DEFAULT" @@ -47,6 +51,8 @@ func TestDefault(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%T/%#v empty==%v", d.val, d.val, d.empty), func(t *testing.T) { + t.Parallel() + if d.empty { assert.Equal(t, def, c.Default(def, d.val)) } else { diff --git a/funcs/crypto_test.go b/funcs/crypto_test.go index 9d6f8975..a317e95b 100644 --- a/funcs/crypto_test.go +++ b/funcs/crypto_test.go @@ -30,6 +30,8 @@ func testCryptoNS() *CryptoFuncs { } func TestPBKDF2(t *testing.T) { + t.Parallel() + c := testCryptoNS() dk, err := c.PBKDF2("password", []byte("IEEE"), "4096", 32) assert.Equal(t, "f42c6fc52df0ebef9ebb4b90b38a5f902e83fe1b135a70e23aed762e9710a12e", dk) @@ -44,6 +46,8 @@ func TestPBKDF2(t *testing.T) { } func TestWPAPSK(t *testing.T) { + t.Parallel() + c := testCryptoNS() dk, err := c.WPAPSK("password", "MySSID") assert.Equal(t, "3a98def84b11644a17ebcc9b17955d2360ce8b8a85b8a78413fc551d722a84e7", dk) @@ -51,6 +55,8 @@ func TestWPAPSK(t *testing.T) { } func TestSHA(t *testing.T) { + t.Parallel() + in := "abc" sha1 := "a9993e364706816aba3e25717850c26c9cd0d89d" sha224 := "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" @@ -70,29 +76,50 @@ func TestSHA(t *testing.T) { } func TestBcrypt(t *testing.T) { + t.Parallel() + if testing.Short() { t.Skip("skipping slow test") } in := "foo" c := testCryptoNS() - actual, err := c.Bcrypt(in) - assert.NoError(t, err) - assert.True(t, strings.HasPrefix(actual, "$2a$10$")) - actual, err = c.Bcrypt(0, in) - assert.NoError(t, err) - assert.True(t, strings.HasPrefix(actual, "$2a$10$")) + t.Run("no arg default", func(t *testing.T) { + t.Parallel() - actual, err = c.Bcrypt(4, in) - assert.NoError(t, err) - assert.True(t, strings.HasPrefix(actual, "$2a$04$")) + actual, err := c.Bcrypt(in) + assert.NoError(t, err) + assert.True(t, strings.HasPrefix(actual, "$2a$10$")) + }) - _, err = c.Bcrypt() - assert.Error(t, err) + t.Run("cost less than min", func(t *testing.T) { + t.Parallel() + + actual, err := c.Bcrypt(0, in) + assert.NoError(t, err) + assert.True(t, strings.HasPrefix(actual, "$2a$10$")) + }) + + t.Run("cost equal to min", func(t *testing.T) { + t.Parallel() + + actual, err := c.Bcrypt(4, in) + assert.NoError(t, err) + assert.True(t, strings.HasPrefix(actual, "$2a$04$")) + }) + + t.Run("no args errors", func(t *testing.T) { + t.Parallel() + + _, err := c.Bcrypt() + assert.Error(t, err) + }) } func TestRSAGenerateKey(t *testing.T) { + t.Parallel() + c := testCryptoNS() _, err := c.RSAGenerateKey(0) assert.Error(t, err) @@ -140,6 +167,8 @@ func TestECDSADerivePublicKey(t *testing.T) { } func TestRSACrypt(t *testing.T) { + t.Parallel() + if testing.Short() { t.Skip("skipping slow test") } diff --git a/funcs/data_test.go b/funcs/data_test.go index fee6494a..1b3a6dce 100644 --- a/funcs/data_test.go +++ b/funcs/data_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateDataFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { diff --git a/funcs/env_test.go b/funcs/env_test.go index 6e47d469..f37ee3da 100644 --- a/funcs/env_test.go +++ b/funcs/env_test.go @@ -10,6 +10,8 @@ import ( ) func TestCreateEnvFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -25,6 +27,8 @@ func TestCreateEnvFuncs(t *testing.T) { } func TestEnvGetenv(t *testing.T) { + t.Parallel() + ef := &EnvFuncs{} expected := os.Getenv("USER") assert.Equal(t, expected, ef.Getenv("USER")) diff --git a/funcs/file_test.go b/funcs/file_test.go index 66c08781..372d00d8 100644 --- a/funcs/file_test.go +++ b/funcs/file_test.go @@ -11,6 +11,8 @@ import ( ) func TestCreateFileFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -26,6 +28,8 @@ func TestCreateFileFuncs(t *testing.T) { } func TestFileExists(t *testing.T) { + t.Parallel() + fs := afero.NewMemMapFs() ff := &FileFuncs{fs: fs} @@ -38,6 +42,8 @@ func TestFileExists(t *testing.T) { } func TestFileIsDir(t *testing.T) { + t.Parallel() + fs := afero.NewMemMapFs() ff := &FileFuncs{fs: fs} @@ -50,6 +56,8 @@ func TestFileIsDir(t *testing.T) { } func TestFileWalk(t *testing.T) { + t.Parallel() + fs := afero.NewMemMapFs() ff := &FileFuncs{fs: fs} diff --git a/funcs/filepath_test.go b/funcs/filepath_test.go index b2994cbd..7799d017 100644 --- a/funcs/filepath_test.go +++ b/funcs/filepath_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateFilePathFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { diff --git a/funcs/filepath_unix_test.go b/funcs/filepath_unix_test.go index 7a8d5239..381e7432 100644 --- a/funcs/filepath_unix_test.go +++ b/funcs/filepath_unix_test.go @@ -10,6 +10,8 @@ import ( ) func TestFilePathFuncs(t *testing.T) { + t.Parallel() + f := &FilePathFuncs{} assert.Equal(t, "bar", f.Base("foo/bar")) assert.Equal(t, "bar", f.Base("/foo/bar")) diff --git a/funcs/filepath_windows_test.go b/funcs/filepath_windows_test.go index 6bd46aee..190dfedb 100644 --- a/funcs/filepath_windows_test.go +++ b/funcs/filepath_windows_test.go @@ -10,6 +10,8 @@ import ( ) func TestFilePathFuncs(t *testing.T) { + t.Parallel() + f := &FilePathFuncs{} assert.Equal(t, "bar", f.Base(`foo\bar`)) assert.Equal(t, "bar", f.Base("C:/foo/bar")) diff --git a/funcs/gcp_test.go b/funcs/gcp_test.go index b79af6d7..b235bce8 100644 --- a/funcs/gcp_test.go +++ b/funcs/gcp_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateGCPFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { diff --git a/funcs/math_test.go b/funcs/math_test.go index f413f5a8..0436c891 100644 --- a/funcs/math_test.go +++ b/funcs/math_test.go @@ -11,6 +11,8 @@ import ( ) func TestCreateMathFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -26,6 +28,8 @@ func TestCreateMathFuncs(t *testing.T) { } func TestAdd(t *testing.T) { + t.Parallel() + m := MathFuncs{} assert.Equal(t, int64(12), m.Add(1, 1, 2, 3, 5)) assert.Equal(t, int64(2), m.Add(1, 1)) @@ -35,6 +39,8 @@ func TestAdd(t *testing.T) { } func TestMul(t *testing.T) { + t.Parallel() + m := MathFuncs{} assert.Equal(t, int64(30), m.Mul(1, 1, 2, 3, 5)) assert.Equal(t, int64(1), m.Mul(1, 1)) @@ -45,6 +51,8 @@ func TestMul(t *testing.T) { } func TestSub(t *testing.T) { + t.Parallel() + m := MathFuncs{} assert.Equal(t, int64(0), m.Sub(1, 1)) assert.Equal(t, int64(-10), m.Sub(-5, 5)) @@ -62,6 +70,8 @@ func mustDiv(a, b interface{}) interface{} { } func TestDiv(t *testing.T) { + t.Parallel() + m := MathFuncs{} _, err := m.Div(1, 0) assert.Error(t, err) @@ -72,12 +82,16 @@ func TestDiv(t *testing.T) { } func TestRem(t *testing.T) { + t.Parallel() + m := MathFuncs{} assert.Equal(t, int64(0), m.Rem(1, 1)) assert.Equal(t, int64(2), m.Rem(5, 3.0)) } func TestPow(t *testing.T) { + t.Parallel() + m := MathFuncs{} assert.Equal(t, int64(4), m.Pow(2, "2")) assert.Equal(t, 2.25, m.Pow(1.5, 2)) @@ -92,6 +106,8 @@ func mustSeq(t *testing.T, n ...interface{}) []int64 { return s } func TestSeq(t *testing.T) { + t.Parallel() + m := MathFuncs{} assert.EqualValues(t, []int64{0, 1, 2, 3}, mustSeq(t, 0, 3)) assert.EqualValues(t, []int64{1, 0}, mustSeq(t, 0)) @@ -103,6 +119,8 @@ func TestSeq(t *testing.T) { } func TestIsIntFloatNum(t *testing.T) { + t.Parallel() + tests := []struct { in interface{} isInt bool @@ -145,6 +163,8 @@ func TestIsIntFloatNum(t *testing.T) { for _, tt := range tests { tt := tt t.Run(fmt.Sprintf("%T(%#v)", tt.in, tt.in), func(t *testing.T) { + t.Parallel() + assert.Equal(t, tt.isInt, m.IsInt(tt.in)) assert.Equal(t, tt.isFloat, m.IsFloat(tt.in)) assert.Equal(t, tt.isInt || tt.isFloat, m.IsNum(tt.in)) @@ -168,6 +188,8 @@ func BenchmarkIsFloat(b *testing.B) { } func TestMax(t *testing.T) { + t.Parallel() + m := MathFuncs{} data := []struct { expected interface{} @@ -185,6 +207,8 @@ func TestMax(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%v==%v", d.n, d.expected), func(t *testing.T) { + t.Parallel() + var actual interface{} if len(d.n) == 1 { actual, _ = m.Max(d.n[0]) @@ -197,6 +221,8 @@ func TestMax(t *testing.T) { } func TestMin(t *testing.T) { + t.Parallel() + m := MathFuncs{} data := []struct { expected interface{} @@ -214,6 +240,8 @@ func TestMin(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%v==%v", d.n, d.expected), func(t *testing.T) { + t.Parallel() + var actual interface{} if len(d.n) == 1 { actual, _ = m.Min(d.n[0]) @@ -226,6 +254,8 @@ func TestMin(t *testing.T) { } func TestContainsFloat(t *testing.T) { + t.Parallel() + m := MathFuncs{} data := []struct { n []interface{} @@ -246,6 +276,8 @@ func TestContainsFloat(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%v==%v", d.n, d.expected), func(t *testing.T) { + t.Parallel() + if d.expected { assert.True(t, m.containsFloat(d.n...)) } else { @@ -256,6 +288,8 @@ func TestContainsFloat(t *testing.T) { } func TestCeil(t *testing.T) { + t.Parallel() + m := MathFuncs{} data := []struct { n interface{} @@ -272,12 +306,16 @@ func TestCeil(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%v==%v", d.n, d.a), func(t *testing.T) { + t.Parallel() + assert.InDelta(t, d.a, m.Ceil(d.n), 1e-12) }) } } func TestFloor(t *testing.T) { + t.Parallel() + m := MathFuncs{} data := []struct { n interface{} @@ -294,12 +332,16 @@ func TestFloor(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%v==%v", d.n, d.a), func(t *testing.T) { + t.Parallel() + assert.InDelta(t, d.a, m.Floor(d.n), 1e-12) }) } } func TestRound(t *testing.T) { + t.Parallel() + m := MathFuncs{} data := []struct { n interface{} @@ -320,12 +362,16 @@ func TestRound(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%v==%v", d.n, d.a), func(t *testing.T) { + t.Parallel() + assert.InDelta(t, d.a, m.Round(d.n), 1e-12) }) } } func TestAbs(t *testing.T) { + t.Parallel() + m := MathFuncs{} data := []struct { n interface{} @@ -345,6 +391,8 @@ func TestAbs(t *testing.T) { for _, d := range data { d := d t.Run(fmt.Sprintf("%#v==%v", d.n, d.a), func(t *testing.T) { + t.Parallel() + assert.Equal(t, d.a, m.Abs(d.n)) }) } diff --git a/funcs/net_test.go b/funcs/net_test.go index fcf03770..e8914fa6 100644 --- a/funcs/net_test.go +++ b/funcs/net_test.go @@ -13,6 +13,8 @@ import ( ) func TestCreateNetFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -28,11 +30,15 @@ func TestCreateNetFuncs(t *testing.T) { } func TestNetLookupIP(t *testing.T) { + t.Parallel() + n := NetFuncs{} assert.Equal(t, "127.0.0.1", must(n.LookupIP("localhost"))) } func TestParseIP(t *testing.T) { + t.Parallel() + n := NetFuncs{} _, err := n.ParseIP("not an IP") assert.Error(t, err) @@ -48,6 +54,8 @@ func TestParseIP(t *testing.T) { } func TestParseIPPrefix(t *testing.T) { + t.Parallel() + n := NetFuncs{} _, err := n.ParseIPPrefix("not an IP") assert.Error(t, err) @@ -61,6 +69,8 @@ func TestParseIPPrefix(t *testing.T) { } func TestParseIPRange(t *testing.T) { + t.Parallel() + n := NetFuncs{} _, err := n.ParseIPRange("not an IP") assert.Error(t, err) diff --git a/funcs/path_test.go b/funcs/path_test.go index 62fec664..f5bd59dd 100644 --- a/funcs/path_test.go +++ b/funcs/path_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreatePathFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -24,6 +26,8 @@ func TestCreatePathFuncs(t *testing.T) { } func TestPathFuncs(t *testing.T) { + t.Parallel() + p := PathFuncs{} assert.Equal(t, "bar", p.Base("foo/bar")) assert.Equal(t, "bar", p.Base("/foo/bar")) diff --git a/funcs/random_test.go b/funcs/random_test.go index f2a3ac2d..f32641c3 100644 --- a/funcs/random_test.go +++ b/funcs/random_test.go @@ -10,6 +10,8 @@ import ( ) func TestCreateRandomFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -25,6 +27,8 @@ func TestCreateRandomFuncs(t *testing.T) { } func TestASCII(t *testing.T) { + t.Parallel() + f := RandomFuncs{} s, err := f.ASCII(0) assert.NoError(t, err) @@ -37,6 +41,8 @@ func TestASCII(t *testing.T) { } func TestAlpha(t *testing.T) { + t.Parallel() + if testing.Short() { t.Skip("skipping slow test") } @@ -53,6 +59,8 @@ func TestAlpha(t *testing.T) { } func TestAlphaNum(t *testing.T) { + t.Parallel() + if testing.Short() { t.Skip("skipping slow test") } @@ -69,6 +77,8 @@ func TestAlphaNum(t *testing.T) { } func TestToCodePoints(t *testing.T) { + t.Parallel() + l, u, err := toCodePoints("a", "b") assert.NoError(t, err) assert.Equal(t, 'a', l) @@ -97,6 +107,8 @@ func TestToCodePoints(t *testing.T) { } func TestString(t *testing.T) { + t.Parallel() + if testing.Short() { t.Skip("skipping slow test") } @@ -140,6 +152,8 @@ func TestString(t *testing.T) { } func TestItem(t *testing.T) { + t.Parallel() + f := RandomFuncs{} _, err := f.Item(nil) assert.Error(t, err) @@ -163,6 +177,8 @@ func TestItem(t *testing.T) { } func TestNumber(t *testing.T) { + t.Parallel() + f := RandomFuncs{} n, err := f.Number() assert.NoError(t, err) @@ -185,6 +201,8 @@ func TestNumber(t *testing.T) { } func TestFloat(t *testing.T) { + t.Parallel() + f := RandomFuncs{} n, err := f.Float() assert.NoError(t, err) diff --git a/funcs/regexp_test.go b/funcs/regexp_test.go index 869cbc9f..cf7852d6 100644 --- a/funcs/regexp_test.go +++ b/funcs/regexp_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateReFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -24,16 +26,22 @@ func TestCreateReFuncs(t *testing.T) { } func TestReplace(t *testing.T) { + t.Parallel() + re := &ReFuncs{} assert.Equal(t, "hello world", re.Replace("i", "ello", "hi world")) } func TestMatch(t *testing.T) { + t.Parallel() + re := &ReFuncs{} assert.True(t, re.Match(`i\ `, "hi world")) } func TestFind(t *testing.T) { + t.Parallel() + re := &ReFuncs{} f, err := re.Find(`[a-z]+`, `foo bar baz`) assert.NoError(t, err) @@ -52,6 +60,8 @@ func TestFind(t *testing.T) { } func TestFindAll(t *testing.T) { + t.Parallel() + re := &ReFuncs{} f, err := re.FindAll(`[a-z]+`, `foo bar baz`) assert.NoError(t, err) @@ -88,6 +98,8 @@ func TestFindAll(t *testing.T) { } func TestSplit(t *testing.T) { + t.Parallel() + re := &ReFuncs{} f, err := re.Split(` `, `foo bar baz`) assert.NoError(t, err) @@ -124,6 +136,8 @@ func TestSplit(t *testing.T) { } func TestReplaceLiteral(t *testing.T) { + t.Parallel() + re := &ReFuncs{} r, err := re.ReplaceLiteral("i", "ello$1", "hi world") assert.NoError(t, err) diff --git a/funcs/sockaddr_test.go b/funcs/sockaddr_test.go index b50228f7..8843f3f0 100644 --- a/funcs/sockaddr_test.go +++ b/funcs/sockaddr_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateSockaddrFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { diff --git a/funcs/strings_test.go b/funcs/strings_test.go index 347ced6f..9da5299e 100644 --- a/funcs/strings_test.go +++ b/funcs/strings_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateStringFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -24,6 +26,8 @@ func TestCreateStringFuncs(t *testing.T) { } func TestReplaceAll(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} assert.Equal(t, "Replaced", @@ -33,6 +37,8 @@ func TestReplaceAll(t *testing.T) { } func TestIndent(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} testdata := []struct { @@ -53,6 +59,8 @@ func TestIndent(t *testing.T) { } func TestTrimPrefix(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} assert.Equal(t, "Bar", @@ -80,6 +88,8 @@ func TestTitle(t *testing.T) { } func TestTrunc(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} assert.Equal(t, "", sf.Trunc(5, "")) assert.Equal(t, "", sf.Trunc(0, nil)) @@ -88,6 +98,8 @@ func TestTrunc(t *testing.T) { } func TestAbbrev(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} _, err := sf.Abbrev() assert.Error(t, err) @@ -136,7 +148,9 @@ func TestSlug(t *testing.T) { } func TestSort(t *testing.T) { + t.Parallel() sf := &StringFuncs{ctx: context.Background()} + in := []string{"foo", "bar", "baz"} out := []string{"bar", "baz", "foo"} assert.Equal(t, out, must(sf.Sort(in))) @@ -145,6 +159,8 @@ func TestSort(t *testing.T) { } func TestQuote(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} testdata := []struct { in interface{} @@ -164,6 +180,8 @@ func TestQuote(t *testing.T) { } func TestShellQuote(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} testdata := []struct { in interface{} @@ -186,6 +204,8 @@ func TestShellQuote(t *testing.T) { } func TestSquote(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} testdata := []struct { in interface{} @@ -205,6 +225,8 @@ func TestSquote(t *testing.T) { } func TestRuneCount(t *testing.T) { + t.Parallel() + sf := &StringFuncs{} n, err := sf.RuneCount("") diff --git a/funcs/test_test.go b/funcs/test_test.go index fc5bbb19..2bcd7039 100644 --- a/funcs/test_test.go +++ b/funcs/test_test.go @@ -9,6 +9,8 @@ import ( ) func TestCreateTestFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -24,6 +26,8 @@ func TestCreateTestFuncs(t *testing.T) { } func TestAssert(t *testing.T) { + t.Parallel() + f := TestNS() _, err := f.Assert(false) assert.Error(t, err) @@ -39,6 +43,8 @@ func TestAssert(t *testing.T) { } func TestRequired(t *testing.T) { + t.Parallel() + f := TestNS() errMsg := "can not render template: a required value was not set" v, err := f.Required("") @@ -82,6 +88,8 @@ func TestRequired(t *testing.T) { } func TestTernary(t *testing.T) { + t.Parallel() + f := TestNS() testdata := []struct { tval, fval, b interface{} @@ -97,6 +105,8 @@ func TestTernary(t *testing.T) { } func TestKind(t *testing.T) { + t.Parallel() + f := TestNS() testdata := []struct { arg interface{} @@ -118,6 +128,8 @@ func TestKind(t *testing.T) { } func TestIsKind(t *testing.T) { + t.Parallel() + f := TestNS() truedata := []struct { arg interface{} diff --git a/funcs/time_test.go b/funcs/time_test.go index 63c5f259..08a9d195 100644 --- a/funcs/time_test.go +++ b/funcs/time_test.go @@ -11,6 +11,8 @@ import ( ) func TestCreateTimeFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -26,6 +28,8 @@ func TestCreateTimeFuncs(t *testing.T) { } func TestParseNum(t *testing.T) { + t.Parallel() + i, f, _ := parseNum("42") assert.Equal(t, int64(42), i) assert.Equal(t, int64(0), f) diff --git a/funcs/uuid_test.go b/funcs/uuid_test.go index 974741d7..88ef52b5 100644 --- a/funcs/uuid_test.go +++ b/funcs/uuid_test.go @@ -10,6 +10,8 @@ import ( ) func TestCreateUUIDFuncs(t *testing.T) { + t.Parallel() + for i := 0; i < 10; i++ { // Run this a bunch to catch race conditions t.Run(strconv.Itoa(i), func(t *testing.T) { @@ -30,6 +32,8 @@ const ( ) func TestV1(t *testing.T) { + t.Parallel() + u := UUIDNS() i, err := u.V1() assert.NoError(t, err) @@ -37,6 +41,8 @@ func TestV1(t *testing.T) { } func TestV4(t *testing.T) { + t.Parallel() + u := UUIDNS() i, err := u.V4() assert.NoError(t, err) @@ -44,6 +50,8 @@ func TestV4(t *testing.T) { } func TestNil(t *testing.T) { + t.Parallel() + u := UUIDNS() i, err := u.Nil() assert.NoError(t, err) @@ -51,6 +59,8 @@ func TestNil(t *testing.T) { } func TestIsValid(t *testing.T) { + t.Parallel() + u := UUIDNS() in := interface{}(false) i, err := u.IsValid(in) @@ -77,6 +87,8 @@ func TestIsValid(t *testing.T) { } func TestParse(t *testing.T) { + t.Parallel() + u := UUIDNS() in := interface{}(false) _, err := u.Parse(in) diff --git a/internal/tests/integration/plugins_test.go b/internal/tests/integration/plugins_test.go index 451274d8..fbab35d8 100644 --- a/internal/tests/integration/plugins_test.go +++ b/internal/tests/integration/plugins_test.go @@ -70,14 +70,19 @@ func TestPlugins_Timeout(t *testing.T) { } tmpDir := setupPluginsTest(t) - _, _, err := cmd(t, "--plugin", "sleep="+tmpDir.Join("sleep.sh"), - "-i", `{{ sleep 10 }}`).run() - assert.ErrorContains(t, err, "plugin timed out") - - _, _, err = cmd(t, "--plugin", "sleep="+tmpDir.Join("sleep.sh"), - "-i", `{{ sleep 2 }}`). - withEnv("GOMPLATE_PLUGIN_TIMEOUT", "500ms").run() - assert.ErrorContains(t, err, "plugin timed out") + + t.Run("default timeout", func(t *testing.T) { + _, _, err := cmd(t, "--plugin", "sleep="+tmpDir.Join("sleep.sh"), + "-i", `{{ sleep 10 }}`).run() + assert.ErrorContains(t, err, "plugin timed out") + }) + + t.Run("envvar timeout", func(t *testing.T) { + _, _, err := cmd(t, "--plugin", "sleep="+tmpDir.Join("sleep.sh"), + "-i", `{{ sleep 2 }}`). + withEnv("GOMPLATE_PLUGIN_TIMEOUT", "500ms").run() + assert.ErrorContains(t, err, "plugin timed out") + }) } func TestPlugins_PipeMode(t *testing.T) { |
