diff --git a/api/conf/conf.go b/api/conf/conf.go index b8ee85af8b..91eb89bc21 100644 --- a/api/conf/conf.go +++ b/api/conf/conf.go @@ -93,7 +93,7 @@ type Config struct { Authentication Authentication } -func InitConf() { +func init() { //go test if workDir := os.Getenv("APISIX_API_WORKDIR"); workDir != "" { WorkDir = workDir diff --git a/api/internal/core/store/store_mock.go b/api/internal/core/store/store_mock.go deleted file mode 100644 index 1591432f18..0000000000 --- a/api/internal/core/store/store_mock.go +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 store - -import ( - "context" - "github.com/stretchr/testify/mock" -) - -type MockInterface struct { - mock.Mock -} - -func (m *MockInterface) Get(key string) (interface{}, error) { - ret := m.Mock.Called(key) - return ret.Get(0), ret.Error(1) -} - -func (m *MockInterface) List(input ListInput) (*ListOutput, error) { - ret := m.Mock.Called(input) - return ret.Get(0).(*ListOutput), ret.Error(1) -} - -func (m *MockInterface) Create(ctx context.Context, obj interface{}) error { - ret := m.Mock.Called(ctx, obj) - return ret.Error(0) -} - -func (m *MockInterface) Update(ctx context.Context, obj interface{}, createOnFail bool) error { - ret := m.Mock.Called(ctx, obj, createOnFail) - return ret.Error(0) -} - -func (m *MockInterface) BatchDelete(ctx context.Context, keys []string) error { - ret := m.Mock.Called(ctx, keys) - return ret.Error(0) -} diff --git a/api/internal/handler/consumer/consumer_test.go b/api/internal/handler/consumer/consumer_test.go index 592582e45d..1f88c52b07 100644 --- a/api/internal/handler/consumer/consumer_test.go +++ b/api/internal/handler/consumer/consumer_test.go @@ -19,10 +19,6 @@ package consumer import ( "encoding/json" - "fmt" - "github.com/shiningrush/droplet/data" - "github.com/stretchr/testify/mock" - "net/http" "testing" "time" @@ -34,53 +30,6 @@ import ( "github.com/apisix/manager-api/internal/core/store" ) -func TestHandler_Get(t *testing.T) { - tests := []struct { - caseDesc string - giveInput *GetInput - giveRet interface{} - giveErr error - wantErr error - wantGetKey string - wantRet interface{} - }{ - { - caseDesc: "normal", - giveInput: &GetInput{Username: "test"}, - wantGetKey: "test", - giveRet: "hello", - wantRet: "hello", - }, - { - caseDesc: "failed", - giveInput: &GetInput{Username: "failed key"}, - wantGetKey: "failed key", - giveErr: fmt.Errorf("get failed"), - wantErr: fmt.Errorf("get failed"), - wantRet: &data.SpecCodeResponse{ - StatusCode: http.StatusInternalServerError, - }, - }, - } - - for _, tc := range tests { - getCalled := true - mStore := &store.MockInterface{} - mStore.On("Get", mock.Anything).Run(func(args mock.Arguments) { - getCalled = true - assert.Equal(t, tc.wantGetKey, args.Get(0), tc.caseDesc) - }).Return(tc.giveRet, tc.giveErr) - - h := Handler{consumerStore: mStore} - ctx := droplet.NewContext() - ctx.SetInput(tc.giveInput) - ret, err := h.Get(ctx) - assert.True(t, getCalled, tc.caseDesc) - assert.Equal(t, tc.wantRet, ret, tc.caseDesc) - assert.Equal(t, tc.wantErr, err, tc.caseDesc) - } -} - func TestConsumer(t *testing.T) { // init err := storage.InitETCDClient([]string{"127.0.0.1:2379"}) diff --git a/api/log/zap.go b/api/log/zap.go index 72244e3717..223a71fb64 100644 --- a/api/log/zap.go +++ b/api/log/zap.go @@ -27,7 +27,7 @@ import ( var logger *zap.SugaredLogger -func InitLog() { +func init() { writeSyncer := fileWriter() encoder := getEncoder() logLevel := getLogLevel() diff --git a/api/main.go b/api/main.go index 0ef2ecb9a8..336aac9230 100644 --- a/api/main.go +++ b/api/main.go @@ -34,8 +34,7 @@ import ( ) func main() { - conf.InitConf() - log.InitLog() + if err := storage.InitETCDClient(conf.ETCDEndpoints); err != nil { log.Error("init etcd client fail: %w", err) panic(err)