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

llamerada-jp / colonio / 18451467117

13 Oct 2025 12:12AM UTC coverage: 62.183% (-6.8%) from 68.948%
18451467117

Pull #107

github

llamerada-jp
wip

Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
Pull Request #107: implement KVS feature

297 of 923 new or added lines in 14 files covered. (32.18%)

5 existing lines in 2 files now uncovered.

3111 of 5003 relevant lines covered (62.18%)

34.5 hits per line

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

80.43
/internal/kvs/simple_kvs_store.go
1
/*
2
 * Copyright 2017- Yuji Ito <llamerada.jp@gmail.com>
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package kvs
17

18
import (
19
        "fmt"
20

21
        "github.com/llamerada-jp/colonio/config"
22
)
23

24
type SimpleKvsStore struct {
25
        stores map[config.KvsSectorKey]map[string][]byte
26
}
27

28
var _ config.KvsStore = (*SimpleKvsStore)(nil)
29

NEW
30
func NewSimpleKvsStore() *SimpleKvsStore {
×
NEW
31
        return &SimpleKvsStore{
×
NEW
32
                stores: make(map[config.KvsSectorKey]map[string][]byte),
×
NEW
33
        }
×
NEW
34
}
×
35

36
func (s *SimpleKvsStore) AllocateSector(sectorKey *config.KvsSectorKey) error {
4✔
37
        if _, exists := s.stores[*sectorKey]; exists {
5✔
38
                return fmt.Errorf("node already exists: %s", sectorKey.SectorID.String())
1✔
39
        }
1✔
40
        s.stores[*sectorKey] = make(map[string][]byte)
3✔
41
        return nil
3✔
42
}
43

44
func (s *SimpleKvsStore) ReleaseSector(sectorKey *config.KvsSectorKey) error {
3✔
45
        if _, exists := s.stores[*sectorKey]; !exists {
4✔
46
                return fmt.Errorf("node does not exist: %s", sectorKey.SectorID.String())
1✔
47
        }
1✔
48
        delete(s.stores, *sectorKey)
2✔
49
        return nil
2✔
50
}
51

52
func (s *SimpleKvsStore) Set(sectorKey *config.KvsSectorKey, key string, value []byte) error {
5✔
53
        if value == nil {
6✔
54
                return fmt.Errorf("value cannot be nil")
1✔
55
        }
1✔
56
        if _, exists := s.stores[*sectorKey]; !exists {
5✔
57
                return fmt.Errorf("node does not exist: %s", sectorKey.SectorID.String())
1✔
58
        }
1✔
59
        s.stores[*sectorKey][key] = value
3✔
60
        return nil
3✔
61
}
62

63
func (s *SimpleKvsStore) Get(sectorKey *config.KvsSectorKey, key string) ([]byte, error) {
4✔
64
        if _, exists := s.stores[*sectorKey]; !exists {
5✔
65
                return nil, fmt.Errorf("node does not exist: %s", sectorKey.SectorID.String())
1✔
66
        }
1✔
67
        value, exists := s.stores[*sectorKey][key]
3✔
68
        if !exists {
4✔
69
                return nil, nil // or return an error if preferred
1✔
70
        }
1✔
71
        return value, nil
2✔
72
}
73

NEW
74
func (s *SimpleKvsStore) Patch(sectorKey *config.KvsSectorKey, key string, value []byte) error {
×
NEW
75
        panic("Patch not implemented in SimpleKvsStore")
×
76
}
77

78
func (s *SimpleKvsStore) Delete(sectorKey *config.KvsSectorKey, key string) error {
3✔
79
        if _, exists := s.stores[*sectorKey]; !exists {
3✔
NEW
80
                return fmt.Errorf("node does not exist: %s", sectorKey.SectorID.String())
×
NEW
81
        }
×
82
        if _, exists := s.stores[*sectorKey][key]; !exists {
4✔
83
                return fmt.Errorf("key does not exist: %s", key)
1✔
84
        }
1✔
85
        delete(s.stores[*sectorKey], key)
2✔
86
        return nil
2✔
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc