-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdGet_test.go
84 lines (74 loc) · 2.12 KB
/
cmdGet_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"context"
"testing"
"github.com/philips-software/gino-keva/internal/event"
"github.com/stretchr/testify/assert"
)
func TestGetCommand(t *testing.T) {
testCases := []struct {
name string
args []string
start []event.Event
wantOutput string
}{
{
name: "Get value of a key",
args: []string{"get", "key"},
start: []event.Event{event.TestDataSetKeyValue},
wantOutput: "value",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
eventsJSON, _ := event.Marshal(&tc.start)
root := NewRootCommand()
ctx := ContextWithGitWrapper(context.Background(), ¬esStub{
logCommitsImplementation: responseStubArgsNone(simpleLogCommitsResponse),
notesListImplementation: responseStubArgsString(simpleNotesListResponse),
notesShowImplementation: responseStubArgsStringString(eventsJSON),
})
args := disableFetch(tc.args)
gotOutput, err := executeCommandContext(ctx, root, args...)
assert.NoError(t, err)
assert.Equal(t, tc.wantOutput, gotOutput)
})
}
}
func TestGetValue(t *testing.T) {
testCases := []struct {
name string
key string
depth uint
start []event.Event
wantValue string
}{
{
name: "Get value of an existing key",
key: "key",
depth: 0,
start: []event.Event{event.TestDataSetKeyValue},
wantValue: "value",
},
{
name: "Get value of a non-existing key",
key: "nonExistingKey",
depth: 0,
start: []event.Event{event.TestDataSetKeyValue},
wantValue: "",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
eventsJSON, _ := event.Marshal(&[]event.Event{event.TestDataSetKeyValue})
gitWrapper := notesStub{
logCommitsImplementation: responseStubArgsNone(simpleLogCommitsResponse),
notesListImplementation: responseStubArgsString(simpleNotesListResponse),
notesShowImplementation: responseStubArgsStringString(eventsJSON),
}
gotValue, err := getValue(&gitWrapper, TestDataDummyRef, tc.key)
assert.NoError(t, err)
assert.Equal(t, tc.wantValue, gotValue)
})
}
}