Skip to content

Commit

Permalink
add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
utkuufuk committed May 31, 2020
1 parent 25b1be2 commit 39830f4
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 16 deletions.
44 changes: 28 additions & 16 deletions internal/trello/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,44 @@ func TestSetExistingCards(t *testing.T) {
numCards map[string]int
}{
{
name: "no labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{createCard([]string{"a"}), createCard([]string{"b"})},
name: "no labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{
newTestCardByLabel([]string{"a"}),
newTestCardByLabel([]string{"b"}),
},
labels: []string{},
numLabels: 0,
},
{
name: "no matching labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{createCard([]string{"a"}), createCard([]string{"b"})},
name: "no matching labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{
newTestCardByLabel([]string{"a"}),
newTestCardByLabel([]string{"b"}),
},
labels: []string{"c"},
numLabels: 1,
numCards: map[string]int{"c": 0},
},
{
name: "all matching labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{createCard([]string{"a"}), createCard([]string{"b"})},
name: "all matching labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{
newTestCardByLabel([]string{"a"}),
newTestCardByLabel([]string{"b"}),
},
labels: []string{"b", "a"},
numLabels: 2,
numCards: map[string]int{"a": 1, "b": 1},
},
{
name: "all matching overlapping labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{createCard([]string{"a", "b"}), createCard([]string{"a", "b"})},
name: "all matching overlapping labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{
newTestCardByLabel([]string{"a", "b"}),
newTestCardByLabel([]string{"a", "b"}),
},
labels: []string{"b", "a"},
numLabels: 2,
numCards: map[string]int{"a": 2, "b": 2},
Expand All @@ -107,9 +119,9 @@ func TestSetExistingCards(t *testing.T) {
name: "some matching labels",
client: Client{existingCards: make(map[string][]Card)},
cards: []*trello.Card{
createCard([]string{"a"}),
createCard([]string{"b"}),
createCard([]string{"c"}),
newTestCardByLabel([]string{"a"}),
newTestCardByLabel([]string{"b"}),
newTestCardByLabel([]string{"c"}),
},
labels: []string{"b", "a"},
numLabels: 2,
Expand Down Expand Up @@ -138,7 +150,7 @@ func TestSetExistingCards(t *testing.T) {
}
}

func createCard(labels []string) *trello.Card {
func newTestCardByLabel(labels []string) *trello.Card {
return &trello.Card{
IDLabels: labels,
}
Expand Down
75 changes: 75 additions & 0 deletions internal/trello/trello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"github.com/adlio/trello"
"github.com/google/go-cmp/cmp"
"github.com/utkuufuk/entrello/internal/config"
)
Expand Down Expand Up @@ -132,3 +133,77 @@ func TestNewClient(t *testing.T) {
})
}
}

func TestCompareWithExisting(t *testing.T) {
label := "label"
tt := []struct {
name string
client Client
cards []Card
label string
numNew int
numStale int
}{
{
name: "only existing cards",
client: Client{existingCards: map[string][]Card{label: {
newTestCardByName("a"),
newTestCardByName("b"),
}}},
cards: []Card{newTestCardByName("a"), newTestCardByName("b")},
numNew: 0,
numStale: 0,
},
{
name: "only new cards",
client: Client{existingCards: map[string][]Card{label: {}}},
cards: []Card{newTestCardByName("a"), newTestCardByName("b")},
numNew: 2,
numStale: 0,
},
{
name: "only stale cards",
client: Client{existingCards: map[string][]Card{label: {
newTestCardByName("a"),
newTestCardByName("b"),
}}},
cards: []Card{},
numNew: 0,
numStale: 2,
},
{
name: "new, stale and existing cards",
client: Client{existingCards: map[string][]Card{label: {
newTestCardByName("a"),
newTestCardByName("b"), // stale
newTestCardByName("c"), // stale
}}},
cards: []Card{
newTestCardByName("a"), // existing
newTestCardByName("d"), // new
},
numNew: 1,
numStale: 2,
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
new, stale := tc.client.CompareWithExisting(tc.cards, label)

if len(new) != tc.numNew {
t.Errorf("wanted %d new cards, got %d", tc.numNew, len(new))
}

if len(stale) != tc.numStale {
t.Errorf("wanted %d stale cards, got %d", tc.numStale, len(stale))
}
})
}
}

func newTestCardByName(name string) *trello.Card {
return &trello.Card{
Name: name,
}
}

0 comments on commit 39830f4

Please sign in to comment.