From 0ae90f3b22dd3e94051eaf6f7b61d2c53581fade Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Wed, 23 Sep 2015 22:23:52 -0700 Subject: [PATCH 1/2] config: add group and window options for locksmith The regular expression for RebootWindowLength comes from https://golang.org/pkg/time/#ParseDuration. --- config/locksmith.go | 11 +++--- config/locksmith_test.go | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 config/locksmith_test.go diff --git a/config/locksmith.go b/config/locksmith.go index 6bf8f85..aa1232d 100644 --- a/config/locksmith.go +++ b/config/locksmith.go @@ -15,8 +15,11 @@ package config type Locksmith struct { - Endpoint string `yaml:"endpoint" env:"LOCKSMITHD_ENDPOINT"` - EtcdCAFile string `yaml:"etcd_cafile" env:"LOCKSMITHD_ETCD_CAFILE"` - EtcdCertFile string `yaml:"etcd_certfile" env:"LOCKSMITHD_ETCD_CERTFILE"` - EtcdKeyFile string `yaml:"etcd_keyfile" env:"LOCKSMITHD_ETCD_KEYFILE"` + Endpoint string `yaml:"endpoint" env:"LOCKSMITHD_ENDPOINT"` + EtcdCAFile string `yaml:"etcd_cafile" env:"LOCKSMITHD_ETCD_CAFILE"` + EtcdCertFile string `yaml:"etcd_certfile" env:"LOCKSMITHD_ETCD_CERTFILE"` + EtcdKeyFile string `yaml:"etcd_keyfile" env:"LOCKSMITHD_ETCD_KEYFILE"` + Group string `yaml:"group" env:"LOCKSMITHD_GROUP"` + RebootWindowStart string `yaml:"window_start" env:"REBOOT_WINDOW_START" valid:"^((?i:sun|mon|tue|wed|thu|fri|sat|sun) )?0*([0-9]|1[0-9]|2[0-3]):0*([0-9]|[1-5][0-9])$"` + RebootWindowLength string `yaml:"window_length" env:"REBOOT_WINDOW_LENGTH" valid:"^[-+]?([0-9]*(\\.[0-9]*)?[a-z]+)+$"` } diff --git a/config/locksmith_test.go b/config/locksmith_test.go new file mode 100644 index 0000000..a8c4eb5 --- /dev/null +++ b/config/locksmith_test.go @@ -0,0 +1,76 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config + +import ( + "testing" +) + +func TestRebootWindowStart(t *testing.T) { + tests := []struct { + value string + + isValid bool + }{ + {value: "Sun 0:0", isValid: true}, + {value: "Sun 00:00", isValid: true}, + {value: "sUn 23:59", isValid: true}, + {value: "mon 0:0", isValid: true}, + {value: "tue 0:0", isValid: true}, + {value: "tues 0:0", isValid: false}, + {value: "wed 0:0", isValid: true}, + {value: "thu 0:0", isValid: true}, + {value: "thur 0:0", isValid: false}, + {value: "fri 0:0", isValid: true}, + {value: "sat 0:0", isValid: true}, + {value: "sat00:00", isValid: false}, + {value: "00:00", isValid: true}, + {value: "10:10", isValid: true}, + {value: "20:20", isValid: true}, + {value: "20:30", isValid: true}, + {value: "20:40", isValid: true}, + {value: "20:50", isValid: true}, + {value: "20:60", isValid: false}, + {value: "24:00", isValid: false}, + } + + for _, tt := range tests { + isValid := (nil == AssertStructValid(Locksmith{RebootWindowStart: tt.value})) + if tt.isValid != isValid { + t.Errorf("bad assert (%s): want %t, got %t", tt.value, tt.isValid, isValid) + } + } +} + +func TestRebootWindowLength(t *testing.T) { + tests := []struct { + value string + + isValid bool + }{ + {value: "1h", isValid: true}, + {value: "1d", isValid: true}, + {value: "0d", isValid: true}, + {value: "0.5h", isValid: true}, + {value: "0.5.0h", isValid: false}, + } + + for _, tt := range tests { + isValid := (nil == AssertStructValid(Locksmith{RebootWindowLength: tt.value})) + if tt.isValid != isValid { + t.Errorf("bad assert (%s): want %t, got %t", tt.value, tt.isValid, isValid) + } + } +} From f63fa39a2d138fd523f37aaa45081b9ab3077369 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Wed, 23 Sep 2015 23:19:47 -0700 Subject: [PATCH 2/2] config: format license --- config/file_test.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/config/file_test.go b/config/file_test.go index e3f0871..60a8efe 100644 --- a/config/file_test.go +++ b/config/file_test.go @@ -1,18 +1,16 @@ -/* - Copyright 2014 CoreOS, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package config