File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ package state_utils
2+
3+ import (
4+ "testing"
5+
6+ "github.com/scott-the-programmer/terraform-provider-minikube/minikube/lib"
7+ "github.com/stretchr/testify/assert"
8+ )
9+
10+ func TestGetMemory (t * testing.T ) {
11+ tests := []struct {
12+ name string
13+ input string
14+ expected int
15+ expectError bool
16+ }{
17+ {
18+ name : "valid memory size - 2Gi" ,
19+ input : "2Gi" ,
20+ expected : 2048 ,
21+ expectError : false ,
22+ },
23+ {
24+ name : "valid memory size - 1024mb" ,
25+ input : "1024mb" ,
26+ expected : 1024 ,
27+ expectError : false ,
28+ },
29+ {
30+ name : "no limit case" ,
31+ input : lib .NoLimit ,
32+ expected : 0 ,
33+ expectError : false ,
34+ },
35+ {
36+ name : "invalid memory size" ,
37+ input : "invalid" ,
38+ expected : 0 ,
39+ expectError : true ,
40+ },
41+ {
42+ name : "negative memory size" ,
43+ input : "-1Gi" ,
44+ expected : 0 ,
45+ expectError : true ,
46+ },
47+ {
48+ name : "empty string" ,
49+ input : "" ,
50+ expected : 0 ,
51+ expectError : true ,
52+ },
53+ }
54+
55+ for _ , tt := range tests {
56+ t .Run (tt .name , func (t * testing.T ) {
57+ result , err := GetMemory (tt .input )
58+
59+ if tt .expectError {
60+ assert .Error (t , err )
61+ } else {
62+ assert .NoError (t , err )
63+ assert .Equal (t , tt .expected , result )
64+ }
65+ })
66+ }
67+ }
You can’t perform that action at this time.
0 commit comments