Skip to content

Commit e2a5bbc

Browse files
committed
close #195 re add the tests for the new git implementation
1 parent 9368c33 commit e2a5bbc

File tree

11 files changed

+152
-506
lines changed

11 files changed

+152
-506
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ _test
1414
*.[568vq]
1515
[568vq].out
1616

17+
*.coverprofile
18+
1719
*.cgo1.go
1820
*.cgo2.c
1921
_cgo_defun.c

executor/executor_test.go

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import (
44
. "github.com/praqma/git-phlow/executor"
55
. "github.com/onsi/ginkgo"
66
. "github.com/onsi/gomega"
7-
"bytes"
8-
"os/exec"
97
)
108

119
var _ = Describe("Executor", func() {
1210

13-
Describe("The ExecuteCommand function", func() {
11+
Describe("The RunCommand function", func() {
1412

1513
Context("called with valid command ls", func() {
1614
It("should not return an error", func() {
@@ -31,53 +29,25 @@ var _ = Describe("Executor", func() {
3129

3230
})
3331

34-
Describe("The ExecPipeCommand function", func() {
32+
Describe("The RunGit function", func() {
3533

36-
Context("should run", func() {
37-
It("with 2 commands", func() {
38-
var buf bytes.Buffer
39-
err := ExecPipeCommand(&buf,
40-
exec.Command("git", "--version"),
41-
exec.Command("sort", ""))
42-
43-
Ω(err).Should(BeNil())
44-
Ω(buf.String()).Should(BeEmpty())
45-
})
46-
})
47-
48-
Context("should run", func() {
49-
It("with 1 command", func() {
50-
var buf bytes.Buffer
51-
err := ExecPipeCommand(&buf, exec.Command("git", "--version"))
34+
Context("called with valid command ls", func() {
35+
It("should not return an error", func() {
36+
_, err := RunGit("git", "--version")
5237

5338
Ω(err).Should(BeNil())
54-
Ω(buf.String()).ShouldNot(BeEmpty())
5539
})
5640
})
5741

58-
Context("should fail", func() {
59-
It("in first function", func() {
60-
var buf bytes.Buffer
61-
62-
err := ExecPipeCommand(&buf,
63-
exec.Command("argh", "blash"),
64-
exec.Command("grep", "stuff"))
65-
42+
Context("called with invalid command", func() {
43+
It("should fail", func() {
44+
output, err := RunGit("lsk", "-lah")
45+
Ω(output).Should(BeEmpty())
6646
Ω(err).ShouldNot(BeNil())
6747
})
68-
})
69-
70-
Context("should fail", func() {
71-
It("in second function", func() {
72-
var buf bytes.Buffer
7348

74-
err := ExecPipeCommand(&buf,
75-
exec.Command("ls", "-lah"),
76-
exec.Command("jklasd", "stuff"))
77-
78-
Ω(err).ShouldNot(BeNil())
79-
})
8049
})
50+
8151
})
8252

8353
})

githandler/branch.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ func Ready(info *BranchInfo, remote string, prefix string) (remoteBranches []str
5757
return
5858
}
5959

60-
61-
62-
6360
//DEPRECETED SECTION - USE GIT
6461
//BranchRename ...
6562
func BranchRename(name string) error {

githandler/branch_test.go

Lines changed: 53 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -7,124 +7,65 @@ import (
77

88
var _ = Describe("Branch", func() {
99

10-
Describe("branch", func() {
11-
gitCmdOut := `
12-
192-move-git-commands-to-new-configuration
13-
delivered/164-detect-github-and-bitbucket-from-config
14-
* master
15-
remotes/origin/HEAD -> origin/master
16-
remotes/origin/master
17-
remotes/origin/version`
10+
Describe("AsList", func() {
1811

19-
It("Something", func() {
20-
osExec = func(command string, argv ...string) (string, error) {
21-
return gitCmdOut, nil
22-
}
12+
It("should return a list of branches", func() {
13+
info := AsList(gitBranchOut)
14+
Ω(info.List).Should(HaveLen(11))
15+
})
16+
17+
It("should return nothing", func() {
18+
info := AsList("læadsjklfjaskldjsakldjaskld")
19+
Ω(info.List).Should(HaveLen(1))
20+
})
2321

24-
info, _ := Branch()
22+
It("should return the current branch ", func() {
23+
info := AsList(gitBranchOut)
2524
Ω(info.Current).Should(Equal("master"))
25+
})
26+
27+
It("should not return master", func() {
28+
info := AsList("læadsjklfjaskldjsakldjaskld")
29+
Ω(info.Current).Should(Equal(""))
30+
})
31+
32+
})
2633

34+
Describe("Delivered", func() {
35+
36+
It("should return delivered branch", func() {
37+
info := AsList(gitBranchOut)
38+
local, remote := Delivered(info, "origin")
39+
Ω(local).Should(HaveLen(2))
40+
Ω(remote).Should(HaveLen(1))
2741
})
42+
2843
})
2944

30-
//BeforeEach(func() {
31-
//
32-
// //Runs before each "It" block
33-
// testfixture.CreateTestRepositoryNoLog(false)
34-
//})
35-
//
36-
//Describe("Branch Function execution", func() {
37-
//
38-
// It("should return a list of branches", func() {
39-
// info, err := Branch()
40-
// Ω(len(info.List)).Should(Equal(11))
41-
// Ω(err).Should(BeNil())
42-
// })
43-
//
44-
// It("branch should return Current branch", func() {
45-
// info, err := Branch()
46-
// Ω(info.Current).Should(Equal("master"))
47-
// Ω(err).Should(BeNil())
48-
// })
49-
//
50-
//})
51-
//
52-
//Describe("Delete Branch Function", func() {
53-
//
54-
// It("should delete local branch and return message", func() {
55-
// output, err := BranchDelete("delivered/1-issue-branch", "", false, false)
56-
// info, _ := Branch()
57-
//
58-
// Ω(err).Should(BeNil())
59-
// Ω(output).ShouldNot(BeEmpty())
60-
// Ω(info.List).Should(HaveLen(10))
61-
// })
62-
//
63-
// It("should delete remote branch and return message", func() {
64-
// _, err1 := BranchDelete("delivered/24-issue-branch", "origin", true, false)
65-
// _, err2 := BranchDelete("delivered/42-issue-branch", "origin", true, false)
66-
// info, _ := Branch()
67-
//
68-
// Ω(err1).Should(BeNil())
69-
// Ω(err2).Should(BeNil())
70-
//
71-
// Ω(info.List).Should(HaveLen(9))
72-
// })
73-
//
74-
//})
75-
//
76-
//Describe("Executing BranchDelivered", func() {
77-
// It("should return lists of delivered branches", func() {
78-
// locals, remotes := BranchDelivered("origin")
79-
// Ω(locals).Should(HaveLen(1))
80-
// Ω(remotes).Should(HaveLen(2))
81-
// Ω(remotes).Should(ContainElement("delivered/24-issue-branch"))
82-
// })
83-
//
84-
//})
85-
//
86-
//Describe("Running BranchDelivered", func() {
87-
//
88-
// It("should return list of ready branches", func() {
89-
// remotes := BranchReady("origin", "ready/")
90-
//
91-
// Ω(remotes).Should(HaveLen(2))
92-
// Ω(remotes).Should(ContainElement("origin/ready/99-issue-branch"))
93-
// })
94-
//
95-
//})
96-
//
97-
//Describe("Running tests on 'BranchTime' function", func() {
98-
//
99-
// It("Should get unix timestamp", func() {
100-
// output, err := BranchTime("origin/ready/99-issue-branch")
101-
// Ω(err).Should(BeNil())
102-
// Ω(output).Should(BeNumerically(">", 100000))
103-
//
104-
// })
105-
//
106-
// It("Should fail geting unix timestamp", func() {
107-
// output, err := BranchTime("bluarh.. not a branch")
108-
// Ω(err).ShouldNot(BeNil())
109-
// Ω(output).Should(Equal(-1))
110-
// })
111-
//
112-
//})
113-
//
114-
//Describe("Executing BranchRemote", func() {
115-
//
116-
// It("should return origin/master", func() {
117-
// output, err := branchRemote()
118-
//
119-
// Ω(err).Should(BeNil())
120-
// Ω(output).Should(Equal("origin/master"))
121-
//
122-
// })
123-
//
124-
//})
125-
//
126-
//AfterEach(func() {
127-
// testfixture.RemoveTestRepositoryNoLog()
128-
//})
45+
Describe("Ready", func() {
46+
47+
It("should return list of ready branches", func() {
48+
info := AsList(gitBranchOut)
49+
ready := Ready(info, "origin", "ready")
50+
51+
Ω(ready).Should(HaveLen(1))
52+
Ω(ready).Should(ContainElement("origin/ready/31-add-documentation-for-docker-compose"))
53+
})
54+
55+
})
12956

13057
})
58+
59+
var gitBranchOut = `
60+
23-add-impl-for-postgres
61+
24-isolate-rest-for-scalability
62+
31-add-documentation-for-docker-compose
63+
delivered/30-change-docker-config-to-k8
64+
delivered/31-add-documentation-for-docker-compose
65+
* master
66+
remotes/origin/HEAD -> origin/master
67+
remotes/origin/master
68+
remotes/origin/ready/31-add-documentation-for-docker-compose
69+
remotes/origin/version
70+
remotes/origin/delivered/31-add-documentation-for-docker-compose
71+
`

0 commit comments

Comments
 (0)