From 60d6c34c2850efb67ad34968c28656d0437d5593 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Sun, 11 Jan 2015 20:18:35 -0800 Subject: [PATCH 1/2] etcdmain: add config tests --- etcdmain/config_test.go | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/etcdmain/config_test.go b/etcdmain/config_test.go index 73947f53e..0840f7715 100644 --- a/etcdmain/config_test.go +++ b/etcdmain/config_test.go @@ -166,3 +166,81 @@ func TestConfigParsingConflictClusteringFlags(t *testing.T) { } } } + +func TestConfigIsNewCluster(t *testing.T) { + tests := []struct { + state string + wIsNew bool + }{ + {clusterStateFlagExisting, false}, + {clusterStateFlagNew, true}, + } + for i, tt := range tests { + cfg := NewConfig() + if err := cfg.clusterState.Set(tt.state); err != nil { + t.Fatalf("#%d: unexpected clusterState.Set error: %v", i, err) + } + if g := cfg.isNewCluster(); g != tt.wIsNew { + t.Errorf("#%d: isNewCluster = %v, want %v", i, g, tt.wIsNew) + } + } +} + +func TestConfigIsProxy(t *testing.T) { + tests := []struct { + proxy string + wIsProxy bool + }{ + {proxyFlagOff, false}, + {proxyFlagReadonly, true}, + {proxyFlagOn, true}, + } + for i, tt := range tests { + cfg := NewConfig() + if err := cfg.proxy.Set(tt.proxy); err != nil { + t.Fatalf("#%d: unexpected proxy.Set error: %v", i, err) + } + if g := cfg.isProxy(); g != tt.wIsProxy { + t.Errorf("#%d: isProxy = %v, want %v", i, g, tt.wIsProxy) + } + } +} + +func TestConfigIsReadonlyProxy(t *testing.T) { + tests := []struct { + proxy string + wIsReadonly bool + }{ + {proxyFlagOff, false}, + {proxyFlagReadonly, true}, + {proxyFlagOn, false}, + } + for i, tt := range tests { + cfg := NewConfig() + if err := cfg.proxy.Set(tt.proxy); err != nil { + t.Fatalf("#%d: unexpected proxy.Set error: %v", i, err) + } + if g := cfg.isReadonlyProxy(); g != tt.wIsReadonly { + t.Errorf("#%d: isReadonlyProxy = %v, want %v", i, g, tt.wIsReadonly) + } + } +} + +func TestConfigShouldFallbackToProxy(t *testing.T) { + tests := []struct { + fallback string + wFallback bool + }{ + {fallbackFlagProxy, true}, + {fallbackFlagExit, false}, + } + for i, tt := range tests { + cfg := NewConfig() + if err := cfg.fallback.Set(tt.fallback); err != nil { + t.Fatalf("#%d: unexpected fallback.Set error: %v", i, err) + } + if g := cfg.shouldFallbackToProxy(); g != tt.wFallback { + t.Errorf("#%d: shouldFallbackToProxy = %v, want %v", i, g, tt.wFallback) + } + } +} From 50395a53fbfaffea1c4c48db1f5e30de27aac2a7 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Mon, 12 Jan 2015 13:34:21 -0800 Subject: [PATCH 2/2] etcdmain: add license --- etcdmain/http.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/etcdmain/http.go b/etcdmain/http.go index fd3f9faee..93f0047a8 100644 --- a/etcdmain/http.go +++ b/etcdmain/http.go @@ -1,3 +1,19 @@ +/* + 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. +*/ + package etcdmain import (