| 116 | } |
| 117 | |
| 118 | func Test_Bytes_UnmarshalYAML(t *testing.T) { |
| 119 | for _, tcase := range []struct { |
| 120 | input string |
| 121 | expected uint64 |
| 122 | }{ |
| 123 | { |
| 124 | input: "1.5GiB\n", |
| 125 | expected: (1024 + 512) * 1024 * 1024, |
| 126 | }, |
| 127 | { |
| 128 | input: "1.5GB\n", |
| 129 | expected: (1024 + 512) * 1024 * 1024, |
| 130 | }, |
| 131 | { |
| 132 | input: "1536MiB\n", |
| 133 | expected: (1024 + 512) * 1024 * 1024, |
| 134 | }, |
| 135 | { |
| 136 | input: "1536MB\n", |
| 137 | expected: (1024 + 512) * 1024 * 1024, |
| 138 | }, |
| 139 | { |
| 140 | input: "1GiB\n", |
| 141 | expected: 1024 * 1024 * 1024, |
| 142 | }, |
| 143 | { |
| 144 | input: "1GB\n", |
| 145 | expected: 1024 * 1024 * 1024, |
| 146 | }, |
| 147 | { |
| 148 | input: "1MiB\n", |
| 149 | expected: 1024 * 1024, |
| 150 | }, |
| 151 | { |
| 152 | input: "1MB\n", |
| 153 | expected: 1024 * 1024, |
| 154 | }, |
| 155 | { |
| 156 | input: "1KiB\n", |
| 157 | expected: 1024, |
| 158 | }, |
| 159 | { |
| 160 | input: "1KB\n", |
| 161 | expected: 1024, |
| 162 | }, |
| 163 | } { |
| 164 | var b Bytes |
| 165 | require.NoError(t, yaml.Unmarshal([]byte(tcase.input), &b)) |
| 166 | require.Equal(t, Bytes(tcase.expected), b) |
| 167 | } |
| 168 | } |