2021-09-19 11:49:54 +00:00
|
|
|
// Copyright (c), the Drone Authors.
|
|
|
|
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
|
2019-02-10 19:00:16 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-30 20:42:06 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2019-01-22 23:44:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBytesSize(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
yaml string
|
|
|
|
size int64
|
|
|
|
text string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
yaml: "1KiB",
|
|
|
|
size: 1024,
|
|
|
|
text: "1KiB",
|
|
|
|
},
|
|
|
|
{
|
2022-09-06 07:25:48 +00:00
|
|
|
yaml: "100MiB",
|
2019-01-22 23:44:17 +00:00
|
|
|
size: 104857600,
|
|
|
|
text: "100MiB",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
yaml: "1024",
|
|
|
|
size: 1024,
|
|
|
|
text: "1KiB",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
in := []byte(test.yaml)
|
|
|
|
out := BytesSize(0)
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
err := yaml.Unmarshal(in, &out)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
return
|
|
|
|
}
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
if got, want := int64(out), test.size; got != want {
|
|
|
|
t.Errorf("Want byte size %d, got %d", want, got)
|
|
|
|
}
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
if got, want := out.String(), test.text; got != want {
|
|
|
|
t.Errorf("Want byte text %s, got %s", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|