luet/tests/helpers/package.go
Ettore Di Giacinto ba0d625b5f 🎨 Port package to types
This refactors DefaultPackage into types.Package and gets rid of the
interface. This is a preceeding for a follow up where accessors will be
removed from the code.
It also does several cleanup, so we get rid also of some unneeded
dependencies.
2022-01-08 00:05:20 +01:00

32 lines
678 B
Go

package helpers
import (
"math/rand"
"strconv"
"time"
"github.com/mudler/luet/pkg/api/core/types"
)
const charset = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var seededRand *rand.Rand = rand.New(
rand.NewSource(time.Now().UnixNano()))
func StringWithCharset(length int, charset string) string {
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}
func String(length int) string {
return StringWithCharset(length, charset)
}
func RandomPackage() *types.Package {
return types.NewPackage(String(5), strconv.Itoa(rand.Intn(100)), []*types.Package{}, []*types.Package{})
}