github.com/drone/runner-go@v1.12.0/manifest/unit_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package manifest 6 7 import ( 8 "testing" 9 10 "github.com/buildkite/yaml" 11 ) 12 13 func TestBytesSize(t *testing.T) { 14 tests := []struct { 15 yaml string 16 size int64 17 text string 18 }{ 19 { 20 yaml: "1KiB", 21 size: 1024, 22 text: "1KiB", 23 }, 24 { 25 yaml: "100Mi", 26 size: 104857600, 27 text: "100MiB", 28 }, 29 { 30 yaml: "1024", 31 size: 1024, 32 text: "1KiB", 33 }, 34 } 35 for _, test := range tests { 36 in := []byte(test.yaml) 37 out := BytesSize(0) 38 err := yaml.Unmarshal(in, &out) 39 if err != nil { 40 t.Error(err) 41 return 42 } 43 if got, want := int64(out), test.size; got != want { 44 t.Errorf("Want byte size %d, got %d", want, got) 45 } 46 if got, want := out.String(), test.text; got != want { 47 t.Errorf("Want byte text %s, got %s", want, got) 48 } 49 } 50 }