Drop `common.CurrentArch()` implementation and use `arch.Current().String()` from the osbuild/images instead. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package common
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPanicOnError(t *testing.T) {
|
|
err := errors.New("Error message")
|
|
assert.PanicsWithValue(t, err, func() { PanicOnError(err) })
|
|
}
|
|
|
|
func TestIsStringInSortedSlice(t *testing.T) {
|
|
assert.True(t, IsStringInSortedSlice([]string{"bart", "homer", "lisa", "marge"}, "homer"))
|
|
assert.False(t, IsStringInSortedSlice([]string{"bart", "lisa", "marge"}, "homer"))
|
|
assert.False(t, IsStringInSortedSlice([]string{"bart", "lisa", "marge"}, ""))
|
|
assert.False(t, IsStringInSortedSlice([]string{}, "homer"))
|
|
}
|
|
|
|
func TestDataSizeToUint64(t *testing.T) {
|
|
cases := []struct {
|
|
input string
|
|
success bool
|
|
output uint64
|
|
}{
|
|
{"123", true, 123},
|
|
{"123 kB", true, 123000},
|
|
{"123 KiB", true, 123 * 1024},
|
|
{"123 MB", true, 123 * 1000 * 1000},
|
|
{"123 MiB", true, 123 * 1024 * 1024},
|
|
{"123 GB", true, 123 * 1000 * 1000 * 1000},
|
|
{"123 GiB", true, 123 * 1024 * 1024 * 1024},
|
|
{"123 TB", true, 123 * 1000 * 1000 * 1000 * 1000},
|
|
{"123 TiB", true, 123 * 1024 * 1024 * 1024 * 1024},
|
|
{"123kB", true, 123000},
|
|
{"123KiB", true, 123 * 1024},
|
|
{" 123 ", true, 123},
|
|
{" 123kB ", true, 123000},
|
|
{" 123KiB ", true, 123 * 1024},
|
|
{"123 KB", false, 0},
|
|
{"123 mb", false, 0},
|
|
{"123 PB", false, 0},
|
|
{"123 PiB", false, 0},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
result, err := DataSizeToUint64(c.input)
|
|
if c.success {
|
|
require.Nil(t, err)
|
|
assert.EqualValues(t, c.output, result)
|
|
} else {
|
|
assert.NotNil(t, err)
|
|
}
|
|
}
|
|
}
|