Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests to utils #192

Merged
merged 7 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions pkg/apis/pingcap.com/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
)

const (
// AnnotationStorageSize is a storage size annotation key
AnnotationStorageSize string = "storage.pingcap.com/size"

// TiKVStateUp represents status of Up of TiKV
TiKVStateUp string = "Up"
// TiKVStateDown represents status of Down of TiKV
TiKVStateDown string = "Down"
// TiKVStateOffline represents status of Offline of TiKV
TiKVStateOffline string = "Offline"
// TiKVStateTombstone represents status of Tombstone of TiKV
TiKVStateTombstone string = "Tombstone"
)

// MemberType represents member type
Expand All @@ -37,16 +38,12 @@ type MemberType string
const (
// PDMemberType is pd container type
PDMemberType MemberType = "pd"

// TiDBMemberType is tidb container type
TiDBMemberType MemberType = "tidb"

// TiKVMemberType is tikv container type
TiKVMemberType MemberType = "tikv"

//PushGatewayMemberType is pushgateway container type
PushGatewayMemberType MemberType = "pushgateway"

// UnknownMemberType is unknown container type
UnknownMemberType MemberType = "unknown"
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/tidbcluster/tidb_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/manager"
"github.com/pingcap/tidb-operator/pkg/util"
apiequality "k8s.io/apimachinery/pkg/api/equality"
errorutils "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -161,7 +160,7 @@ func (tcc *defaultTidbClusterControl) IsTiKVAvailable(tc *v1alpha1.TidbCluster)

var availableNum int32
for _, store := range tc.Status.TiKV.Stores {
if store.State == util.StoreUpState {
if store.State == v1alpha1.TiKVStateUp {
availableNum++
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/manager/member/tikv_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/pkg/util"
apps "k8s.io/api/apps/v1beta1"
corelisters "k8s.io/client-go/listers/core/v1"
)
Expand Down Expand Up @@ -86,7 +85,7 @@ func (tsd *tikvScaler) ScaleIn(tc *v1alpha1.TidbCluster, oldSet *apps.StatefulSe
resetReplicas(newSet, oldSet)
return err
}
if state != util.StoreOfflineState {
if state != v1alpha1.TiKVStateOffline {
if err := tsd.pdControl.GetPDClient(tc).DeleteStore(id); err != nil {
resetReplicas(newSet, oldSet)
return err
Expand Down
7 changes: 3 additions & 4 deletions pkg/manager/member/tikv_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/pkg/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -284,7 +283,7 @@ func TestTiKVScalerScaleIn(t *testing.T) {
storeFun: func(tc *v1alpha1.TidbCluster) {
normalStoreFun(tc)
store := tc.Status.TiKV.Stores["1"]
store.State = util.StoreOfflineState
store.State = v1alpha1.TiKVStateOffline
tc.Status.TiKV.Stores["1"] = store
},
delStoreErr: false,
Expand Down Expand Up @@ -379,7 +378,7 @@ func normalStoreFun(tc *v1alpha1.TidbCluster) {
"1": {
ID: "1",
PodName: ordinalPodName(v1alpha1.TiKVMemberType, tc.GetName(), 4),
State: util.StoreUpState,
State: v1alpha1.TiKVStateUp,
},
}
}
Expand All @@ -389,7 +388,7 @@ func tombstoneStoreFun(tc *v1alpha1.TidbCluster) {
"1": {
ID: "1",
PodName: ordinalPodName(v1alpha1.TiKVMemberType, tc.GetName(), 4),
State: util.StoreTombstoneState,
State: v1alpha1.TiKVStateTombstone,
},
}
}
Expand Down
11 changes: 0 additions & 11 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ var (
}
)

const (
// StoreUpState is state when tikv store is normal
StoreUpState = "Up"
// StoreOfflineState is state when tikv store is offline
StoreOfflineState = "Offline"
// StoreDownState is state when tikv store is down
StoreDownState = "Down"
// StoreTombstoneState is state when tikv store is tombstone
StoreTombstoneState = "Tombstone"
)

// AntiAffinityForPod creates a PodAntiAffinity with antiLabels
func AntiAffinityForPod(namespace string, antiLabels map[string]string) *corev1.PodAntiAffinity {
keys := []string{}
Expand Down
Loading