Skip to content

Commit

Permalink
(wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Jun 13, 2024
1 parent db8b5ed commit 10b0507
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 55 deletions.
68 changes: 32 additions & 36 deletions pkg/cmd/task/done/done_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func TestCmdDone(t *testing.T) {
}
}

dFactory := func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f
}

tts := []struct {
name string
args []string
Expand All @@ -38,59 +44,48 @@ func TestCmdDone(t *testing.T) {
err string
}{
{
name: "task id required",
args: []string{"-p=cli"},
err: `requires arg task`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id required",
args: []string{"-p=cli"},
err: `requires arg task`,
factory: dFactory,
},
{
name: "project required",
args: []string{"task"},
err: `"project" not set`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "project required",
args: []string{"task"},
err: `"project" not set`,
factory: dFactory,
},
{
name: "project not empty",
args: []string{"task", "-p= "},
err: `project should not be empty`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "project not empty",
args: []string{"task", "-p= "},
err: `project should not be empty`,
factory: dFactory,
},
{
name: "task id not empty",
args: []string{" ", "-p=cli"},
err: `task id/name should not be empty`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id not empty",
args: []string{" ", "-p=cli"},
err: `task id/name should not be empty`,
factory: dFactory,
},
{
name: "task id not empty (nice try)",
args: []string{"not-empty", " ", "-p=cli"},
err: `task id/name should not be empty`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id not empty (nice try)",
args: []string{"not-empty", " ", "-p=cli"},
err: `task id/name should not be empty`,
factory: dFactory,
},
{
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-p=OK", "done"},
err: "flags can't be used together.*format.*json.*quiet",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-p=OK", "done"},
err: "flags can't be used together.*format.*json.*quiet",
factory: dFactory,
},
{
name: "client error",
err: "client error",
args: []string{"done", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").
Return("w", nil)

Expand All @@ -104,6 +99,7 @@ func TestCmdDone(t *testing.T) {
args: []string{"done", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").
Return("", errors.New("workspace error"))
return f
Expand Down
38 changes: 20 additions & 18 deletions pkg/cmd/task/quick-add/quick-add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func TestCmdQuickAdd(t *testing.T) {
}
}

dFactory := func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f
}

tts := []struct {
name string
args []string
Expand All @@ -35,35 +41,30 @@ func TestCmdQuickAdd(t *testing.T) {
err string
}{
{
name: "only one format",
args: []string{"--format={}", "-q", "-j", "OK", "-p=OK"},
err: "flags can't be used together.*format.*json.*quiet",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "only one format",
args: []string{"--format={}", "-q", "-j", "OK", "-p=OK"},
err: "flags can't be used together.*format.*json.*quiet",
factory: dFactory,
},
{
name: "name required",
args: []string{"-p=OK"},
err: `requires arg name`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "name required",
args: []string{"-p=OK"},
err: `requires arg name`,
factory: dFactory,
},
{
name: "project required",
args: []string{"OK"},
err: `"project" not set`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "project required",
args: []string{"OK"},
err: `"project" not set`,
factory: dFactory,
},
{
name: "client error",
err: "client error",
args: []string{"a", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.EXPECT().Client().Return(nil, errors.New("client error"))
return f
},
Expand All @@ -74,6 +75,7 @@ func TestCmdQuickAdd(t *testing.T) {
args: []string{"a", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.EXPECT().Client().Return(mocks.NewMockClient(t), nil)
f.EXPECT().GetWorkspaceID().
Return("", errors.New("workspace error"))
Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/time-entry/report/today/today_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func TestCmdToday(t *testing.T) {
args: "--format {} --json --csv -q --md " +
"--duration-float --duration-formatted",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f
},
err: errors.New(
"the following flags can't be used together: " +
Expand All @@ -55,6 +57,7 @@ func TestCmdToday(t *testing.T) {
args: "-q",
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetUserID").Return("user-id", nil)
f.On("GetWorkspaceID").Return("w-id", nil)

Expand Down Expand Up @@ -84,6 +87,7 @@ func TestCmdToday(t *testing.T) {
name: "all of them, but fails",
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetUserID").Return("user-id", nil)
f.On("GetWorkspaceID").Return("w-id", nil)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
Expand Down

0 comments on commit 10b0507

Please sign in to comment.