File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,15 @@ func (m *MemorySize) Set(value string) error {
3838 }
3939
4040 size , err := strconv .Atoi (value )
41- if err != nil || size < 0 {
41+
42+ if err != nil {
4243 return fmt .Errorf ("invalid memory size: %s" , value )
4344 }
4445
46+ if size <= 0 {
47+ return fmt .Errorf ("memory size must be greater than 0" )
48+ }
49+
4550 * m = MemorySize (size * multiplier )
4651 return nil
4752}
Original file line number Diff line number Diff line change @@ -35,10 +35,11 @@ func TestMemorySize_Set(t *testing.T) {
3535 var ms MemorySize
3636
3737 // Test inputs with invalid values
38- Expect (ms .Set ("10XYZ" )).To (Not (BeNil ())) // Unknown unit
39- Expect (ms .Set ("ABC" )).To (Not (BeNil ())) // Non-numeric input
40- Expect (ms .Set ("" )).To (Not (BeNil ())) // Empty input
41- Expect (ms .Set ("-5MB" )).To (Not (BeNil ())) // Negative value
38+ Expect (ms .Set ("10XYZ" )).To (MatchError ("invalid memory size: 10XYZ" ))
39+ Expect (ms .Set ("ABC" )).To (MatchError ("invalid memory size: ABC" ))
40+ Expect (ms .Set ("" )).To (MatchError ("invalid memory size: " ))
41+ Expect (ms .Set ("-5MB" )).To (MatchError ("memory size must be greater than 0" ))
42+ Expect (ms ).To (Equal (MemorySize (0 )))
4243 })
4344
4445 t .Run ("boundary cases" , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments