Skip to content

Commit 05307e4

Browse files
tests
1 parent 1dc942d commit 05307e4

File tree

2 files changed

+63
-51
lines changed

2 files changed

+63
-51
lines changed

namer/namer.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ var (
3636

3737
// Results represents Namer working result.
3838
type Results struct {
39-
isSingle bool // True if result contains only one object name.
40-
isSingleName string // Cached name when isSingle=true.
41-
result map[string][]Key // Grouped keys: object name -> key list.
39+
IsSingle bool // True if result contains only one object name.
40+
IsSingleName string // Cached name when isSingle=true.
41+
Result map[string][]Key // Grouped keys: object name -> key list.
4242
}
4343

4444
// SelectSingle gets keys for single-name case (if applicable).
4545
func (r *Results) SelectSingle() ([]Key, bool) {
46-
if r.isSingle {
47-
return r.result[r.isSingleName], true
46+
if r.IsSingle {
47+
return r.Result[r.IsSingleName], true
4848
}
4949

5050
return nil, false
@@ -53,7 +53,7 @@ func (r *Results) SelectSingle() ([]Key, bool) {
5353
// Items return iterator over all name->keys groups.
5454
func (r *Results) Items() iter.Seq2[string, []Key] {
5555
return func(yield func(str string, res []Key) bool) {
56-
for i, v := range r.result {
56+
for i, v := range r.Result {
5757
if !yield(i, v) {
5858
return
5959
}
@@ -63,7 +63,7 @@ func (r *Results) Items() iter.Seq2[string, []Key] {
6363

6464
// Select gets keys for a specific object name.
6565
func (r *Results) Select(name string) ([]Key, bool) {
66-
if i, ok := r.result[name]; ok {
66+
if i, ok := r.Result[name]; ok {
6767
return i, true
6868
}
6969

@@ -72,7 +72,7 @@ func (r *Results) Select(name string) ([]Key, bool) {
7272

7373
// Len returns the number of unique object names.
7474
func (r *Results) Len() int {
75-
return len(r.result)
75+
return len(r.Result)
7676
}
7777

7878
//-----------------------------------------------------------------------------
@@ -103,20 +103,20 @@ func NewDefaultNamer(prefix string, hasher hasher.Hasher, signerverifier verific
103103
func (n *DefaultNamer) GenerateMulti(kvs []kv.KeyValue) Results {
104104
var out Results
105105

106-
out.result = make(map[string][]Key)
106+
out.Result = make(map[string][]Key)
107107

108108
for _, keyvalue := range kvs {
109109
keys, err := n.Generate(keyvalue)
110110
if err != nil {
111111
continue
112112
}
113113

114-
out.result[string(keyvalue.Key)] = keys
114+
out.Result[string(keyvalue.Key)] = keys
115115
}
116116

117117
if len(kvs) == 1 {
118-
out.isSingle = true
119-
out.isSingleName = string(kvs[0].Key)
118+
out.IsSingle = true
119+
out.IsSingleName = string(kvs[0].Key)
120120
}
121121

122122
return out
@@ -168,22 +168,22 @@ func (n *DefaultNamer) Generate(keyvalue kv.KeyValue) ([]Key, error) {
168168

169169
// ParseKVMulti convert set of raw KVs to set of KVs with original key/values.
170170
func (n *DefaultNamer) ParseKVMulti(kvs []kv.KeyValue) ([]kv.KeyValue, error) {
171-
var results Results
172-
173171
out := make([]kv.KeyValue, 0, len(kvs)/keysPerName)
174172

173+
var temp_results Results
174+
175175
// Combine keys in threes to get complete set of data to decode the original value.
176176
for _, keyvalue := range kvs {
177177
key, err := n.ParseKV(keyvalue)
178178
if err != nil {
179179
return nil, err
180180
}
181181

182-
results.result[key.Name()] = append(results.result[key.Name()], key)
182+
temp_results.Result[key.Name()] = append(temp_results.Result[key.Name()], key)
183183
}
184184

185185
// Decoding.
186-
for _, keyset := range results.Items() {
186+
for _, keyset := range temp_results.Items() {
187187
keyvalue, err := n.DecodeKey(keyset)
188188
if err != nil {
189189
return nil, err

namer/namer_test.go

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,59 @@ func TestGenerate(t *testing.T) {
2121
prefix string
2222
name string
2323
value string
24-
expected []kv.KeyValue
24+
expected namer.Results
2525
}{
2626
{
2727
"/tt/config",
2828
"all",
2929
"value",
30-
[]kv.KeyValue{
31-
{
32-
Key: []byte("/tt/config/all"),
33-
Value: []byte("value"),
34-
ModRevision: 1,
35-
},
36-
{
37-
Key: []byte("/tt/config/hash/sha256/all"),
38-
Value: []byte{
39-
0xa3, 0xc7, 0xb9, 0x70, 0xc5, 0x1b, 0x9b, 0xee, 0x4e, 0xdc, 0x82, 0xfe, 0x2d, 0x79, 0xf8, 0x15,
40-
0x24, 0x8d, 0xbb, 0x2e, 0x3a, 0x9b, 0x26, 0x63, 0x6e, 0xf2, 0xa3, 0xbe, 0xed, 0xbf, 0xc7, 0x58,
30+
namer.Results{
31+
IsSingle: true,
32+
IsSingleName: "all",
33+
Result: map[string][]namer.Key{
34+
"all": []namer.Key{
35+
namer.DefaultKey{
36+
name: "/tt/config/all",
37+
keytype: 1,
38+
property: "",
39+
raw: []uint8{
40+
0x2d, 0x20, 0x31, 0x31, 0x38, 0xa, 0x2d, 0x20, 0x39, 0x37, 0xa, 0x2d, 0x20, 0x31, 0x30, 0x38,
41+
0xa, 0x2d, 0x20, 0x31, 0x31, 0x37, 0xa, 0x2d, 0x20, 0x31, 0x30, 0x31, 0xa,
42+
},
43+
},
44+
namer.DefaultKey{
45+
name: "/tt/config/hash/sha256/all",
46+
keytype: 2,
47+
property: "sha256",
48+
raw: []uint8{
49+
0xa3, 0xc7, 0xb9, 0x70, 0xc5, 0x1b, 0x9b, 0xee, 0x4e, 0xdc, 0x82, 0xfe, 0x2d, 0x79, 0xf8, 0x15,
50+
0x24, 0x8d, 0xbb, 0x2e, 0x3a, 0x9b, 0x26, 0x63, 0x6e, 0xf2, 0xa3, 0xbe, 0xed, 0xbf, 0xc7, 0x58,
51+
},
52+
},
53+
namer.DefaultKey{
54+
name: "/tt/config/sig/all",
55+
keytype: 3,
56+
property: "",
57+
raw: []uint8{
58+
0x2d, 0x38, 0x3b, 0xa1, 0x4a, 0xd3, 0x57, 0x18, 0x21, 0x63, 0x80, 0x2b, 0x99, 0xcc, 0xf1, 0x0f,
59+
0x4f, 0x7d, 0x7e, 0xb2, 0x23, 0x89, 0xc9, 0x8c, 0xb6, 0x73, 0xd0, 0x8e, 0x37, 0x98, 0x7f, 0xef,
60+
0xfb, 0x70, 0x1c, 0x25, 0x7d, 0x68, 0x03, 0x44, 0x73, 0x14, 0xe8, 0x3e, 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+
0xe1, 0x72, 0xb1, 0xf9, 0x5a, 0x31, 0xb8, 0xa1, 0x72, 0x54, 0xbf, 0x4d, 0xc8, 0xa7, 0x07, 0xf5,
73+
0x05, 0xf0, 0x67, 0xeb, 0x32, 0xda, 0x41, 0x82, 0xeb, 0xdb, 0xcb, 0x96, 0xfe, 0x95, 0x19, 0x8e,
74+
},
75+
},
4176
},
42-
ModRevision: 1,
43-
},
44-
{
45-
Key: []byte("/tt/config/sig/all"),
46-
Value: []byte{
47-
0x2c, 0xd0, 0x10, 0x8d, 0x3b, 0x43, 0x3b, 0x8e, 0x60, 0x22, 0x09, 0x78, 0x86, 0xf2, 0xe1, 0xd1,
48-
0xcd, 0xea, 0xa0, 0x9b, 0xd0, 0x92, 0xb1, 0xc5, 0x90, 0x3a, 0x85, 0xeb, 0xd2, 0xe8, 0x3f, 0x43,
49-
0x6d, 0xe2, 0x08, 0x1d, 0xfb, 0xc6, 0xd9, 0x04, 0x6e, 0x2c, 0x11, 0xa7, 0x6f, 0xcb, 0x27, 0x66,
50-
0x0e, 0x6b, 0xc8, 0xbb, 0xe1, 0x77, 0x33, 0xa3, 0x65, 0x49, 0xbf, 0xc7, 0x6e, 0x18, 0x0e, 0x4d,
51-
0x0f, 0x20, 0x0b, 0x51, 0xf9, 0x50, 0xdf, 0x76, 0x2d, 0x22, 0x0e, 0xa2, 0x1c, 0xa5, 0xdf, 0x49,
52-
0xbd, 0x2b, 0xbd, 0xc7, 0xa6, 0x99, 0x8d, 0x55, 0x3b, 0xf8, 0xf4, 0xa2, 0xbf, 0xda, 0xf8, 0xe9,
53-
0xf7, 0x41, 0xa8, 0xc4, 0xa9, 0x34, 0xef, 0x0b, 0xa4, 0xb5, 0x96, 0x08, 0x60, 0x8c, 0xa1, 0xdb,
54-
0x4e, 0xd0, 0x5a, 0xed, 0x78, 0x3f, 0x0f, 0x9e, 0x74, 0x09, 0xf9, 0x75, 0x07, 0xbb, 0x5b, 0xe8,
55-
0xbe, 0x44, 0xbf, 0x07, 0xf7, 0x9f, 0x26, 0x12, 0xb2, 0x02, 0xbf, 0x96, 0xdf, 0x18, 0x35, 0x46,
56-
0x67, 0x9f, 0x7b, 0xe8, 0xdc, 0xfe, 0x7f, 0xac, 0xad, 0x5b, 0x94, 0x63, 0x0f, 0x1b, 0x03, 0xe6,
57-
0x3f, 0x80, 0xb8, 0x9a, 0x7f, 0x5a, 0x4e, 0x1c, 0x7b, 0x51, 0x9b, 0x76, 0x3b, 0x50, 0xcd, 0x22,
58-
0x95, 0xca, 0xf0, 0x0a, 0xac, 0xf8, 0x61, 0xbb, 0x9f, 0xe6, 0x36, 0xe5, 0xde, 0x6c, 0xb8, 0xfb,
59-
0x3e, 0xb7, 0x94, 0x53, 0x20, 0x1e, 0xbc, 0xfa, 0x0a, 0x6e, 0x29, 0xcd, 0x91, 0xe5, 0xf3, 0xa9,
60-
0x1a, 0xb2, 0x87, 0x97, 0x6f, 0x93, 0x77, 0x48, 0x08, 0xe3, 0xf9, 0x9d, 0xd3, 0x44, 0x18, 0x82,
61-
0x58, 0x66, 0xf7, 0x41, 0x64, 0x41, 0x1d, 0xae, 0xef, 0x30, 0x3e, 0x6e, 0xf9, 0xeb, 0x0d, 0xbe,
62-
0xb8, 0x90, 0x76, 0x79, 0x36, 0x44, 0x60, 0x0d, 0xa2, 0x15, 0xcc, 0xc8, 0x28, 0x0f, 0x5d, 0x36,
63-
},
64-
ModRevision: 1,
6577
},
6678
},
6779
},

0 commit comments

Comments
 (0)