Skip to content

Commit

Permalink
Add v0 compatibility functions (#82)
Browse files Browse the repository at this point in the history
* Add v0 compatibility functions

bunch of dependants still use a version before generics
this will help migration to be done progressively

* lovely lint
  • Loading branch information
cesartw authored Aug 22, 2024
1 parent ea51bfb commit 7869872
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 25 deletions.
10 changes: 5 additions & 5 deletions aesutil/aesutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ func TestInvalidKeysAndData(t *testing.T) {
data := []byte(testPlaintext)
_, err := Encrypt("", data)
if err == nil {
t.Errorf("Encrypt succeeded with an empty key")
t.Error("Encrypt succeeded with an empty key")
}

// Decrypt with empty key
_, err = Decrypt("", testCiphertext)
if err == nil {
t.Errorf("Decrypt succeeded with an empty key")
t.Error("Decrypt succeeded with an empty key")
}

// Decrypt with an incorrect key
Expand All @@ -48,13 +48,13 @@ func TestInvalidKeysAndData(t *testing.T) {
// Decrypt an short string (i.e. smaller than block size)
_, err = Decrypt(testKeyString, "aaaabbbbcccc")
if err == nil {
t.Errorf("Decrypt succeeded with an invalid key size")
t.Error("Decrypt succeeded with an invalid key size")
}

// Decrypt a non-base64 string
_, err = Decrypt(testKeyString, fmt.Sprintf("%s#@?`", testCiphertext))
if err == nil {
t.Errorf("Decrypt succeeded with an invalid base64 string")
t.Error("Decrypt succeeded with an invalid base64 string")
}
}

Expand Down Expand Up @@ -87,7 +87,7 @@ func TestEncryptAndDecrypt(t *testing.T) {
t.Fatal("Decrypt failed, plaintext result is nil")
}
if string(plain) != testData {
t.Fatalf(diff.Cmp(testData, string(plain)))
t.Fatal(diff.Cmp(testData, string(plain)))
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion goutil/goutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func ResolveWildcard(path string, mode build.ImportMode) ([]*build.Package, erro

// Gather a list of directories with *.go files.
goDirs := make(map[string]struct{})
err = filepath.Walk(root.Dir, func(path string, info os.FileInfo, err error) error {
err = filepath.Walk(root.Dir, func(path string, info os.FileInfo, _ error) error {
if !strings.HasSuffix(path, ".go") || info.IsDir() || strings.Contains(path, "/vendor/") {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion ioutilx/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func TestCopyTree(t *testing.T) {

err := CopyTree("test", "test_copytree", &CopyTreeOptions{
Symlinks: false,
Ignore: func(path string, fi []os.FileInfo) []string {
Ignore: func(_ string, _ []os.FileInfo) []string {
return []string{"fifo"}
},
CopyFunction: Copy,
Expand Down
2 changes: 1 addition & 1 deletion jsonutil/jsonutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestMustUnmarshal(t *testing.T) {
defer func() {
rec := recover()
if rec == nil {
t.Errorf("no panic?")
t.Error("no panic?")
}
}()

Expand Down
2 changes: 1 addition & 1 deletion maputil/maputil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestSwap(t *testing.T) {
t.Run(fmt.Sprintf("test-%v", i), func(t *testing.T) {
got := Swap(tc.in)
if !reflect.DeepEqual(got, tc.expected) {
t.Errorf(diff.Cmp(tc.expected, got))
t.Error(diff.Cmp(tc.expected, got))
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions ptrutil/ptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestDereference_Int(t *testing.T) {
for i, test := range tests {
t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) {
if got := Dereference(test.ptr); got != test.expected {
t.Errorf(diff.Cmp(test.expected, got))
t.Error(diff.Cmp(test.expected, got))
}
})
}
Expand All @@ -47,7 +47,7 @@ func TestDereference_String(t *testing.T) {
for i, test := range tests {
t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) {
if got := Dereference(test.ptr); got != test.expected {
t.Errorf(diff.Cmp(test.expected, got))
t.Error(diff.Cmp(test.expected, got))
}
})
}
Expand Down
85 changes: 85 additions & 0 deletions sliceutil/compatibility.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package sliceutil

// JoinInt see Join
// Deprecated: use Join
func JoinInt(ints []int64) string {
return Join(ints)
}

// UniqInt64 see Unique
// Deprecated: use Unique
func UniqInt64(list []int64) []int64 {
return Unique(list)
}

// UniqString see Unique
// Deprecated: use Unique
func UniqString(list []string) []string {
return Unique(list)
}

// UniqueMergeSlices see MergeUnique
// Deprecated: use MergeUnique
func UniqueMergeSlices(s [][]int64) (result []int64) {
return MergeUnique(s)
}

// InStringSlice see Contains
// Deprecated: use Contains
func InStringSlice(list []string, str string) bool {
return Contains(list, str)
}

// InIntSlice see Contains
// Deprecated: use Contains
func InIntSlice(list []int, i int) bool {
return Contains(list, i)
}

// InInt64Slice see Contains
// Deprecated: use Contains
func InInt64Slice(list []int64, i int64) bool {
return Contains(list, i)
}

// RepeatString see Repeat
// Deprecated: use Repeat
func RepeatString(s string, n int) (r []string) {
return Repeat(s, n)
}

// ChooseString see Choose
// Deprecated: use Choose
func ChooseString(l []string) string {
return Choose(l)
}

// FilterString see Filter
// Deprecated: use Filter
func FilterString(list []string, fun func(string) bool) []string {
return Filter(list, fun)
}

// RemoveString see Remove
// Deprecated: use Remove
func RemoveString(list []string, s string) (out []string) {
return Remove(list, s)
}

// FilterStringEmpty see FilterEmpty
// Deprecated: use FilterEmpty
func FilterStringEmpty(e string) bool {
return FilterEmpty(e)
}

// FilterInt see Filter
// Deprecated: use Filter
func FilterInt(list []int64, fun func(int64) bool) []int64 {
return Filter(list, fun)
}

// StringMap see Map
// Deprecated: use Map
func StringMap(list []string, f func(string) string) []string {
return Map(list, f)
}
Loading

0 comments on commit 7869872

Please sign in to comment.