fix postgresql spec tests
This commit is contained in:
		
							parent
							
								
									312f9e47b3
								
							
						
					
					
						commit
						41b774c004
					
				|  | @ -1,6 +1,7 @@ | ||||||
| package spec | package spec | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"bytes" | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"reflect" | 	"reflect" | ||||||
|  | @ -9,13 +10,12 @@ import ( | ||||||
| 
 | 
 | ||||||
| 	"k8s.io/client-go/pkg/api/unversioned" | 	"k8s.io/client-go/pkg/api/unversioned" | ||||||
| 	"k8s.io/client-go/pkg/api/v1" | 	"k8s.io/client-go/pkg/api/v1" | ||||||
| 	"bytes" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var parseTimeTests = []struct { | var parseTimeTests = []struct { | ||||||
| 	in                 string | 	in  string | ||||||
| 	out                time.Time | 	out time.Time | ||||||
| 	err                error | 	err error | ||||||
| }{ | }{ | ||||||
| 	{"16:08", mustParseTime("16:08"), nil}, | 	{"16:08", mustParseTime("16:08"), nil}, | ||||||
| 	{"11:00", mustParseTime("11:00"), nil}, | 	{"11:00", mustParseTime("11:00"), nil}, | ||||||
|  | @ -26,9 +26,9 @@ var parseTimeTests = []struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var parseWeekdayTests = []struct { | var parseWeekdayTests = []struct { | ||||||
| 	in                 string | 	in  string | ||||||
| 	out                time.Weekday | 	out time.Weekday | ||||||
| 	err                error | 	err error | ||||||
| }{ | }{ | ||||||
| 	{"Wed", time.Wednesday, nil}, | 	{"Wed", time.Wednesday, nil}, | ||||||
| 	{"Sunday", time.Weekday(0), errors.New("incorrect weekday")}, | 	{"Sunday", time.Weekday(0), errors.New("incorrect weekday")}, | ||||||
|  | @ -58,21 +58,31 @@ var maintenanceWindows = []struct { | ||||||
| 	err error | 	err error | ||||||
| }{{[]byte(`"Tue:10:00-20:00"`), | }{{[]byte(`"Tue:10:00-20:00"`), | ||||||
| 	MaintenanceWindow{ | 	MaintenanceWindow{ | ||||||
| 		Weekday: time.Tuesday, | 		Everyday:  false, | ||||||
| 		StartTime:    mustParseTime("10:00"), | 		Weekday:   time.Tuesday, | ||||||
| 		EndTime:      mustParseTime("20:00"), | 		StartTime: mustParseTime("10:00"), | ||||||
|  | 		EndTime:   mustParseTime("20:00"), | ||||||
| 	}, nil}, | 	}, nil}, | ||||||
| 	{[]byte(`"Mon:10:00-10:00"`), | 	{[]byte(`"Mon:10:00-10:00"`), | ||||||
| 		MaintenanceWindow{ | 		MaintenanceWindow{ | ||||||
| 			Weekday: time.Monday, | 			Everyday:  false, | ||||||
| 			StartTime:    mustParseTime("10:00"), | 			Weekday:   time.Monday, | ||||||
| 			EndTime:      mustParseTime("10:00"), | 			StartTime: mustParseTime("10:00"), | ||||||
|  | 			EndTime:   mustParseTime("10:00"), | ||||||
| 		}, nil}, | 		}, nil}, | ||||||
| 	{[]byte(`"Sun:00:00-00:00"`), | 	{[]byte(`"Sun:00:00-00:00"`), | ||||||
| 		MaintenanceWindow{ | 		MaintenanceWindow{ | ||||||
| 			Weekday: time.Sunday, | 			Everyday:  false, | ||||||
| 			StartTime:    mustParseTime("00:00"), | 			Weekday:   time.Sunday, | ||||||
| 			EndTime:      mustParseTime("00:00"), | 			StartTime: mustParseTime("00:00"), | ||||||
|  | 			EndTime:   mustParseTime("00:00"), | ||||||
|  | 		}, nil}, | ||||||
|  | 	{[]byte(`"01:00-10:00"`), | ||||||
|  | 		MaintenanceWindow{ | ||||||
|  | 			Everyday:  true, | ||||||
|  | 			Weekday:   time.Sunday, | ||||||
|  | 			StartTime: mustParseTime("01:00"), | ||||||
|  | 			EndTime:   mustParseTime("10:00"), | ||||||
| 		}, nil}, | 		}, nil}, | ||||||
| 	{[]byte(`"Mon:12:00-11:00"`), MaintenanceWindow{}, errors.New(`'From' time must be prior to the 'To' time`)}, | 	{[]byte(`"Mon:12:00-11:00"`), MaintenanceWindow{}, errors.New(`'From' time must be prior to the 'To' time`)}, | ||||||
| 	{[]byte(`"Wed:33:00-00:00"`), MaintenanceWindow{}, errors.New(`could not parse start time: parsing time "33:00": hour out of range`)}, | 	{[]byte(`"Wed:33:00-00:00"`), MaintenanceWindow{}, errors.New(`could not parse start time: parsing time "33:00": hour out of range`)}, | ||||||
|  | @ -168,7 +178,8 @@ var unmarshalCluster = []struct { | ||||||
|     }, |     }, | ||||||
|     "maintenanceWindows": [ |     "maintenanceWindows": [ | ||||||
|       "Mon:01:00-06:00", |       "Mon:01:00-06:00", | ||||||
|       "Sat:00:00-04:00" |       "Sat:00:00-04:00", | ||||||
|  |       "05:00-05:15" | ||||||
|     ] |     ] | ||||||
|   } |   } | ||||||
| }`), | }`), | ||||||
|  | @ -214,21 +225,28 @@ var unmarshalCluster = []struct { | ||||||
| 				NumberOfInstances:   2, | 				NumberOfInstances:   2, | ||||||
| 				Users:               map[string]UserFlags{"zalando": {"superuser", "createdb"}}, | 				Users:               map[string]UserFlags{"zalando": {"superuser", "createdb"}}, | ||||||
| 				MaintenanceWindows: []MaintenanceWindow{{ | 				MaintenanceWindows: []MaintenanceWindow{{ | ||||||
| 					Weekday: time.Monday, | 					Everyday:  false, | ||||||
| 					StartTime:    mustParseTime("01:00"), | 					Weekday:   time.Monday, | ||||||
| 					EndTime:      mustParseTime("06:00"), | 					StartTime: mustParseTime("01:00"), | ||||||
|  | 					EndTime:   mustParseTime("06:00"), | ||||||
|  | 				}, { | ||||||
|  | 					Everyday:  false, | ||||||
|  | 					Weekday:   time.Saturday, | ||||||
|  | 					StartTime: mustParseTime("00:00"), | ||||||
|  | 					EndTime:   mustParseTime("04:00"), | ||||||
| 				}, | 				}, | ||||||
| 					{ | 					{ | ||||||
| 						Weekday: time.Saturday, | 						Everyday:  true, | ||||||
| 						StartTime:    mustParseTime("00:00"), | 						Weekday: time.Sunday, | ||||||
| 						EndTime:      mustParseTime("04:00"), | 						StartTime: mustParseTime("05:00"), | ||||||
|  | 						EndTime:   mustParseTime("05:15"), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				ClusterName: "testcluster1", | 				ClusterName: "testcluster1", | ||||||
| 			}, | 			}, | ||||||
| 			Error: nil, | 			Error: nil, | ||||||
| 		}, | 		}, | ||||||
| 		[]byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"volume":{"size":"5Gi","storageClass":"SSD"},"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host    all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00"]}}`), nil}, | 		[]byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"volume":{"size":"5Gi","storageClass":"SSD"},"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host    all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00","05:00-05:15"]}}`), nil}, | ||||||
| 	{ | 	{ | ||||||
| 		[]byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1","metadata": {"name": "teapot-testcluster1"}, "spec": {"teamId": "acid"}}`), | 		[]byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1","metadata": {"name": "teapot-testcluster1"}, "spec": {"teamId": "acid"}}`), | ||||||
| 		Postgresql{ | 		Postgresql{ | ||||||
|  | @ -337,7 +355,6 @@ func TestWeekdayTime(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| func TestClusterName(t *testing.T) { | func TestClusterName(t *testing.T) { | ||||||
| 	for _, tt := range clusterNames { | 	for _, tt := range clusterNames { | ||||||
| 		name, err := extractClusterName(tt.in, tt.inTeam) | 		name, err := extractClusterName(tt.in, tt.inTeam) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue