Skip to content

Commit

Permalink
store kv: add test (apache#313)
Browse files Browse the repository at this point in the history
Co-authored-by: l00618052 <[email protected]>
  • Loading branch information
Dantlian and l00618052 authored Jan 17, 2024
1 parent caa96dc commit 92aee20
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.51.2
version: v1.55.2
args: --enable gofmt,gocyclo,goimports,dupl,gosec --timeout 5m --skip-dirs=examples,test --skip-files=.*_test.go$
static-checks:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions server/datasource/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"context"
"errors"
"fmt"
"github.com/apache/servicecomb-kie/server/datasource/rbac"
"github.com/go-chassis/openlog"

"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/server/datasource/rbac"
"github.com/go-chassis/openlog"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion server/datasource/local/counter/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package counter

import (
"context"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"os"
"path"
"strconv"

"github.com/apache/servicecomb-kie/server/datasource/local/file"
"github.com/go-chassis/openlog"
)

Expand Down
31 changes: 20 additions & 11 deletions server/datasource/local/file/fileprocess.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
/*
* 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 file

import (
log "github.com/go-chassis/openlog"
"io/fs"
"os"
"path"
"path/filepath"
"strings"
"sync"

log "github.com/go-chassis/openlog"
)

var FileRootPath = "/data/kvs"
Expand Down Expand Up @@ -238,16 +256,7 @@ func CountInDomain(dir string) (int, error) {
count := 0
for _, projectFolder := range files {
if projectFolder.IsDir() {
kvs, err := os.ReadDir(path.Join(dir, projectFolder.Name()))
if err != nil {
log.Error("failed to read directory " + dir + ", " + err.Error())
return 0, err
}
for _, kv := range kvs {
if kv.IsDir() {
count++
}
}
count++
}
}
// count kv numbers
Expand Down
7 changes: 3 additions & 4 deletions server/datasource/local/history/history_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ package history
import (
"context"
"encoding/json"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"path"
"strconv"

"github.com/apache/servicecomb-kie/server/datasource/auth"
"github.com/go-chassis/openlog"

"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/server/datasource"
"github.com/apache/servicecomb-kie/server/datasource/auth"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"github.com/go-chassis/openlog"
)

// Dao is the implementation
Expand Down
10 changes: 5 additions & 5 deletions server/datasource/local/kv/kv_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ import (
"context"
"encoding/json"
"fmt"
"regexp"
"strings"
"sync"
"time"

"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/pkg/stringutil"
"github.com/apache/servicecomb-kie/server/datasource"
"github.com/go-chassis/openlog"
goCache "github.com/patrickmn/go-cache"
"go.etcd.io/etcd/api/v3/mvccpb"
"regexp"
"strings"
"sync"
"time"
)

type IDSet map[string]struct{}
Expand Down Expand Up @@ -95,7 +96,6 @@ func (kc *Cache) GetKvDoc(kv *mvccpb.KeyValue) (*model.KVDoc, error) {
return kvDoc, nil
}


func (kc *Cache) GetCacheKey(domain, project string, labels map[string]string) string {
labelFormat := stringutil.FormatMap(labels)
inputKey := strings.Join([]string{
Expand Down
4 changes: 2 additions & 2 deletions server/datasource/local/kv/kv_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package kv
import (
"context"
"encoding/json"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"os"
"path"
"regexp"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/apache/servicecomb-kie/pkg/util"
"github.com/apache/servicecomb-kie/server/datasource"
"github.com/apache/servicecomb-kie/server/datasource/auth"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"github.com/go-chassis/openlog"
)

Expand All @@ -51,7 +51,7 @@ func (s *Dao) Create(ctx context.Context, kv *model.KVDoc, options ...datasource
}))
return nil, err
}

kvCache.CachePut([]*model.KVDoc{kv})
return kv, nil
}

Expand Down
5 changes: 3 additions & 2 deletions server/datasource/local/track/polling_detail_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ package track
import (
"context"
"encoding/json"
"os"
"path"

"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/server/datasource"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"github.com/go-chassis/openlog"
"os"
"path"
)

// Dao is the implementation
Expand Down
2 changes: 1 addition & 1 deletion server/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ package db
import (
"crypto/tls"
"errors"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"time"

"github.com/apache/servicecomb-kie/server/config"
"github.com/apache/servicecomb-kie/server/config/tlsutil"
"github.com/apache/servicecomb-kie/server/datasource/local/file"
"github.com/go-chassis/cari/db"
dconfig "github.com/go-chassis/cari/db/config"
"github.com/go-chassis/openlog"
Expand Down

0 comments on commit 92aee20

Please sign in to comment.