@@ -30,6 +30,7 @@ func TestNewCustomMachineType(t *testing.T) {
3030 testCases := []struct {
3131 name string
3232 expectCustom bool
33+ expectErr bool
3334 expectCPU int64
3435 expectMemory int64
3536 }{
@@ -39,33 +40,84 @@ func TestNewCustomMachineType(t *testing.T) {
3940 expectCPU : 2 ,
4041 expectMemory : 2816 * units .MiB ,
4142 },
43+ {
44+ name : "custom-2-2816-ext" ,
45+ expectCustom : true ,
46+ expectCPU : 2 ,
47+ expectMemory : 2816 * units .MiB ,
48+ },
4249 {
4350 name : "n2-custom-2-2816" ,
4451 expectCustom : true ,
4552 expectCPU : 2 ,
4653 expectMemory : 2816 * units .MiB ,
4754 },
4855 {
49- name : "other-a2-2816" ,
56+ name : "n2-custom-2-2816-ext" ,
57+ expectCustom : true ,
58+ expectCPU : 2 ,
59+ expectMemory : 2816 * units .MiB ,
60+ },
61+ {
62+ name : "e2-custom-medium-2816" ,
63+ expectCustom : true ,
64+ expectCPU : 2 ,
65+ expectMemory : 2816 * units .MiB ,
66+ },
67+ {
68+ name : "e2-custom-micro-2048" ,
69+ expectCustom : true ,
70+ expectCPU : 2 ,
71+ expectMemory : 2048 * units .MiB ,
72+ },
73+ {
74+ name : "e2-custom-small-2048" ,
75+ expectCustom : true ,
76+ expectCPU : 2 ,
77+ expectMemory : 2048 * units .MiB ,
78+ },
79+ {
80+ name : "e2-custom" ,
81+ expectCustom : true ,
82+ expectErr : true ,
83+ },
84+ {
85+ name : "e2-custom-8" ,
86+ expectCustom : true ,
87+ expectErr : true ,
88+ },
89+ {
90+ name : "e2-custom-abc-2048" ,
91+ expectCustom : true ,
92+ expectErr : true ,
93+ },
94+ {
95+ name : "other-a2-2816" ,
96+ expectCustom : false ,
97+ expectErr : true ,
5098 },
5199 {
52- name : "other-2-2816" ,
100+ name : "other-2-2816" ,
101+ expectCustom : false ,
102+ expectErr : true ,
53103 },
54104 {
55- name : "n1-standard-8" ,
105+ name : "n1-standard-8" ,
106+ expectCustom : false ,
107+ expectErr : true ,
56108 },
57109 }
58110
59111 for _ , tc := range testCases {
60112 t .Run (tc .name , func (t * testing.T ) {
61113 assert .Equal (t , tc .expectCustom , IsCustomMachine (tc .name ))
62114 m , err := NewCustomMachineType (tc .name )
63- if tc .expectCustom {
115+ if tc .expectErr {
116+ assert .Error (t , err )
117+ } else {
64118 assert .NoError (t , err )
65119 assert .Equal (t , tc .expectCPU , m .CPU )
66120 assert .Equal (t , tc .expectMemory , m .Memory )
67- } else {
68- assert .Error (t , err )
69121 }
70122 })
71123 }
@@ -89,10 +141,30 @@ func TestGetMachineFamily(t *testing.T) {
89141 machineType : "n2-custom-2-2816" ,
90142 wantFamily : "n2" ,
91143 },
144+ "custom machine type with family prefix and ext suffix" : {
145+ machineType : "n2-custom-2-2816-ext" ,
146+ wantFamily : "n2" ,
147+ },
92148 "custom machine type without family prefix" : {
93149 machineType : "custom-2-2816" ,
94150 wantFamily : "n1" ,
95151 },
152+ "custom machine type without family prefix with ext suffix" : {
153+ machineType : "custom-2-2816-ext" ,
154+ wantFamily : "n1" ,
155+ },
156+ "e2 custom medium type" : {
157+ machineType : "e2-custom-medium-2816" ,
158+ wantFamily : "e2" ,
159+ },
160+ "e2 custom small type" : {
161+ machineType : "e2-custom-small-2048" ,
162+ wantFamily : "e2" ,
163+ },
164+ "e2 custom micro type" : {
165+ machineType : "e2-custom-micro-2048" ,
166+ wantFamily : "e2" ,
167+ },
96168 "invalid machine type" : {
97169 machineType : "nodashes" ,
98170 wantErr : cmpopts .AnyError ,
0 commit comments