• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / servicecomb-kie / 229

04 Jan 2020 02:15AM UTC coverage: 51.887% (+1.7%) from 50.196%
229

Pull #61

travis-ci

web-flow
SCB-1700 fix wrong query param parsing
Pull Request #61: SCB-1700 support kv revision management

40 of 74 new or added lines in 7 files covered. (54.05%)

20 existing lines in 2 files now uncovered.

605 of 1166 relevant lines covered (51.89%)

1.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/server/service/mongo/history/dao.go
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17

18
package history
19

20
import (
21
        "context"
22
        "github.com/apache/servicecomb-kie/pkg/model"
23
        "github.com/apache/servicecomb-kie/server/service"
24
        "github.com/apache/servicecomb-kie/server/service/mongo/session"
25
        "github.com/go-mesh/openlogging"
26
        "go.mongodb.org/mongo-driver/bson"
27
        "go.mongodb.org/mongo-driver/mongo/options"
28
)
29

NEW
30
func getHistoryByKeyID(ctx context.Context, filter bson.M) ([]*model.KVDoc, error) {
×
NEW
31
        collection := session.GetDB().Collection(session.CollectionKVRevision)
×
32
        cur, err := collection.Find(ctx, filter, options.Find().SetSort(map[string]interface{}{
×
NEW
33
                "revision": -1,
×
34
        }))
×
35
        if err != nil {
×
36
                return nil, err
×
37
        }
×
NEW
38
        kvs := make([]*model.KVDoc, 0)
×
39
        var exist bool
×
40
        for cur.Next(ctx) {
×
NEW
41
                var elem model.KVDoc
×
42
                err := cur.Decode(&elem)
×
43
                if err != nil {
×
NEW
44
                        openlogging.Error("decode error: " + err.Error())
×
45
                        return nil, err
×
46
                }
×
47
                exist = true
×
NEW
48
                kvs = append(kvs, &elem)
×
49
        }
50
        if !exist {
×
51
                return nil, service.ErrRevisionNotExist
×
52
        }
×
NEW
53
        return kvs, nil
×
54
}
55

56
//AddHistory add kv history
NEW
57
func AddHistory(ctx context.Context, kv *model.KVDoc) error {
×
58
        ctx, cancel := context.WithTimeout(ctx, session.Timeout)
×
59
        defer cancel()
×
NEW
60
        collection := session.GetDB().Collection(session.CollectionKVRevision)
×
NEW
61
        _, err := collection.InsertOne(ctx, kv)
×
62
        if err != nil {
×
NEW
63
                openlogging.Error(err.Error())
×
NEW
64
                return err
×
65
        }
×
NEW
66
        return nil
×
67
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc