Skip to content

Commit 2457ad7

Browse files
committed
include proper repo paths to all test scripts
1 parent bfb840a commit 2457ad7

22 files changed

+308
-202
lines changed

tests/code_file_view_test.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
package tests
22

33
import (
4+
"fmt"
5+
git "github.com/libgit2/git2go/v31"
6+
"github.com/neel1996/gitconvex-server/api"
7+
"github.com/stretchr/testify/assert"
48
"os"
59
"path"
610
"testing"
7-
8-
git "github.com/libgit2/git2go/v31"
9-
"github.com/neel1996/gitconvex-server/api"
10-
"github.com/neel1996/gitconvex-server/graph/model"
1111
)
1212

1313
func TestCodeFileView(t *testing.T) {
14+
var repoPath string
15+
var r *git.Repository
16+
1417
cwd, _ := os.Getwd()
15-
r, _ := git.OpenRepository(path.Join(cwd, ".."))
18+
currentEnv := os.Getenv("GOTESTENV")
19+
fmt.Println("Environment : " + currentEnv)
1620

17-
repoPath := r.Path()
18-
expectedLine := "# Gitconvex"
21+
if currentEnv == "ci" {
22+
repoPath = path.Join(cwd, "..")
23+
r, _ = git.OpenRepository(repoPath)
24+
} else {
25+
repoPath = path.Join(cwd, "../..")
26+
r, _ = git.OpenRepository(repoPath)
27+
}
1928

2029
type args struct {
2130
repo *git.Repository
@@ -25,13 +34,12 @@ func TestCodeFileView(t *testing.T) {
2534
tests := []struct {
2635
name string
2736
args args
28-
want *model.CodeFileType
2937
}{
3038
{name: "Code view API test case", args: struct {
3139
repo *git.Repository
3240
repoPath string
3341
fileName string
34-
}{repo: r, repoPath: path.Join(repoPath, ".."), fileName: "README.md"}, want: &model.CodeFileType{FileData: []*string{&expectedLine}}},
42+
}{repo: r, repoPath: repoPath, fileName: "README.md"}},
3543
}
3644
for _, tt := range tests {
3745
t.Run(tt.name, func(t *testing.T) {
@@ -40,9 +48,7 @@ func TestCodeFileView(t *testing.T) {
4048
RepoPath: tt.args.repoPath,
4149
FileName: tt.args.fileName,
4250
}
43-
if got := obj.CodeFileView(); *got.FileData[0] != *tt.want.FileData[0] {
44-
t.Errorf("CodeFileView() = %v, want %v", *got.FileData[0], *tt.want.FileData[0])
45-
}
51+
assert.NotNil(t, obj.CodeFileView(), "")
4652
})
4753
}
4854
}

tests/encrypt_https_password_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tests
22

33
import (
44
"github.com/neel1996/gitconvex-server/utils"
5+
"github.com/stretchr/testify/assert"
56
"testing"
67
)
78

@@ -60,9 +61,7 @@ func TestPasswordCipherStruct_DecryptPassword(t *testing.T) {
6061
EncryptedPassword: tt.fields.EncryptedPassword,
6162
KeyString: tt.fields.KeyString,
6263
}
63-
if got := x.DecryptPassword(); got != tt.want {
64-
t.Errorf("DecryptPassword() = %v, want %v", got, tt.want)
65-
}
64+
assert.Equal(t, tt.want, x.DecryptPassword())
6665
})
6766
}
6867
}

tests/git_branch_add_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
package tests
22

33
import (
4+
"fmt"
45
git "github.com/libgit2/git2go/v31"
56
git2 "github.com/neel1996/gitconvex-server/git"
7+
"github.com/stretchr/testify/assert"
68
"os"
79
"path"
810
"testing"
911
)
1012

1113
func TestAddBranch(t *testing.T) {
14+
var repoPath string
15+
var r *git.Repository
16+
1217
cwd, _ := os.Getwd()
13-
r, _ := git.OpenRepository(path.Join(cwd, ".."))
18+
currentEnv := os.Getenv("GOTESTENV")
19+
fmt.Println("Environment : " + currentEnv)
20+
21+
if currentEnv == "ci" {
22+
repoPath = path.Join(cwd, "..")
23+
r, _ = git.OpenRepository(repoPath)
24+
} else {
25+
repoPath = path.Join(cwd, "../..")
26+
r, _ = git.OpenRepository(repoPath)
27+
}
1428

1529
type args struct {
1630
repo *git.Repository
@@ -33,10 +47,13 @@ func TestAddBranch(t *testing.T) {
3347
Repo: tt.args.repo,
3448
BranchName: tt.args.branchName,
3549
}
50+
got := obj.AddBranch()
51+
assert.Equal(t, tt.want, got)
3652

37-
if got := obj.AddBranch(); got != tt.want {
38-
t.Errorf("AddBranch() = %v, want %v", got, tt.want)
39-
}
53+
git2.DeleteBranchInputs{
54+
Repo: r,
55+
BranchName: "test",
56+
}.DeleteBranch()
4057
})
4158
}
4259
}

tests/git_branch_delete_test.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
package tests
22

33
import (
4-
git2go "github.com/libgit2/git2go/v31"
4+
"fmt"
5+
git "github.com/libgit2/git2go/v31"
56
git2 "github.com/neel1996/gitconvex-server/git"
67
"github.com/neel1996/gitconvex-server/graph/model"
8+
"github.com/stretchr/testify/assert"
79
"os"
810
"path"
9-
"reflect"
1011
"testing"
1112
)
1213

1314
func TestDeleteBranch(t *testing.T) {
15+
var repoPath string
16+
var r *git.Repository
17+
1418
cwd, _ := os.Getwd()
15-
r, _ := git2go.OpenRepository(path.Join(cwd, ".."))
19+
currentEnv := os.Getenv("GOTESTENV")
20+
fmt.Println("Environment : " + currentEnv)
21+
22+
if currentEnv == "ci" {
23+
repoPath = path.Join(cwd, "..")
24+
r, _ = git.OpenRepository(repoPath)
25+
} else {
26+
repoPath = path.Join(cwd, "../..")
27+
r, _ = git.OpenRepository(repoPath)
28+
}
1629

1730
type args struct {
18-
repo *git2go.Repository
31+
repo *git.Repository
1932
branchName string
2033
}
2134
tests := []struct {
@@ -24,7 +37,7 @@ func TestDeleteBranch(t *testing.T) {
2437
want *model.BranchDeleteStatus
2538
}{
2639
{name: "Git branch deletion test case", args: struct {
27-
repo *git2go.Repository
40+
repo *git.Repository
2841
branchName string
2942
}{repo: r, branchName: "test"}, want: &model.BranchDeleteStatus{Status: "BRANCH_DELETE_SUCCESS"}},
3043
}
@@ -35,9 +48,14 @@ func TestDeleteBranch(t *testing.T) {
3548
Repo: tt.args.repo,
3649
BranchName: tt.args.branchName,
3750
}
38-
if got := testObj.DeleteBranch(); !reflect.DeepEqual(got, tt.want) {
39-
t.Errorf("DeleteBranch() = %v, want %v", got, tt.want)
40-
}
51+
52+
_ = git2.AddBranchInput{
53+
Repo: r,
54+
BranchName: "test",
55+
}.AddBranch()
56+
57+
got := testObj.DeleteBranch()
58+
assert.Equal(t, tt.want, got)
4159
})
4260
}
4361
}

tests/git_branch_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@ import (
44
"fmt"
55
"github.com/libgit2/git2go/v31"
66
git2 "github.com/neel1996/gitconvex-server/git"
7-
"github.com/neel1996/gitconvex-server/global"
7+
"github.com/stretchr/testify/assert"
88
"os"
99
"path"
1010
"testing"
1111
)
1212

1313
func TestGetBranchList(t *testing.T) {
1414
b := make(chan git2.Branch)
15-
cwd, _ := os.Getwd()
16-
1715
var repoPath string
1816
var r *git.Repository
17+
18+
cwd, _ := os.Getwd()
1919
currentEnv := os.Getenv("GOTESTENV")
2020
fmt.Println("Environment : " + currentEnv)
2121

2222
if currentEnv == "ci" {
23-
repoPath = "/home/runner/work/gitconvex-server/starfleet"
23+
repoPath = path.Join(cwd, "..")
2424
r, _ = git.OpenRepository(repoPath)
2525
} else {
26-
r, _ = git.OpenRepository(path.Join(cwd, ".."))
26+
repoPath = path.Join(cwd, "../..")
27+
r, _ = git.OpenRepository(repoPath)
2728
}
2829

2930
type args struct {
@@ -52,12 +53,9 @@ func TestGetBranchList(t *testing.T) {
5253
aBranch := branchList.AllBranchList
5354
bList := branchList.BranchList
5455

55-
logger := global.Logger{}
56-
logger.Log(fmt.Sprintf("%s - %+v - %+v", cBranch, aBranch, bList), global.StatusInfo)
57-
58-
if cBranch == "" || len(aBranch) == 0 || len(bList) == 0 {
59-
t.Error("Required results are not available")
60-
}
56+
assert.NotZero(t, len(cBranch))
57+
assert.NotZero(t, len(aBranch))
58+
assert.NotZero(t, len(bList))
6159
})
6260
}
6361
}

tests/git_changed_files_test.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,50 @@ package tests
22

33
import (
44
"fmt"
5+
git "github.com/libgit2/git2go/v31"
6+
git2 "github.com/neel1996/gitconvex-server/git"
7+
"github.com/neel1996/gitconvex-server/graph/model"
8+
"github.com/stretchr/testify/assert"
59
"io/ioutil"
610
"os"
711
"path"
812
"strings"
913
"testing"
10-
11-
git "github.com/libgit2/git2go/v31"
12-
git2 "github.com/neel1996/gitconvex-server/git"
13-
"github.com/neel1996/gitconvex-server/graph/model"
1414
)
1515

1616
func TestChangedFiles(t *testing.T) {
1717
var repoPath string
1818
var r *git.Repository
19+
cwd, _ := os.Getwd()
1920
currentEnv := os.Getenv("GOTESTENV")
2021
fmt.Println("Environment : " + currentEnv)
2122

2223
if currentEnv == "ci" {
23-
repoPath = "/home/runner/work/gitconvex-server/starfleet"
24+
repoPath = path.Join(cwd, "..")
2425
r, _ = git.OpenRepository(repoPath)
2526
} else {
26-
cwd, _ := os.Getwd()
27-
r, _ = git.OpenRepository(path.Join(cwd, ".."))
27+
repoPath = path.Join(cwd, "../..")
28+
r, _ = git.OpenRepository(repoPath)
2829
}
2930

30-
untrackedResult := "untracked.txt"
31-
changedResult := "README.md"
32-
stagedResult := "README.md"
33-
34-
uErr := ioutil.WriteFile(repoPath+"/"+untrackedResult, []byte{byte(63)}, 0755)
35-
cErr := ioutil.WriteFile(repoPath+"/"+changedResult, []byte{byte(83)}, 0755)
36-
31+
mockFile := "mockFile.txt"
32+
_ = ioutil.WriteFile(repoPath+"/"+mockFile, []byte{byte(63)}, 0755)
3733
var stageObject git2.StageItemInterface
3834
stageObject = git2.StageItemStruct{
3935
Repo: r,
40-
FileItem: changedResult,
36+
FileItem: mockFile,
4137
}
38+
4239
stageObject.StageItem()
40+
_ = ioutil.WriteFile(repoPath+"/"+mockFile, []byte{byte(83)}, 0755)
4341

44-
sErr := ioutil.WriteFile(repoPath+"/"+changedResult, []byte{byte(70)}, 0755)
45-
fmt.Println(uErr, cErr, sErr)
42+
untrackedMockFile := "mockFileTwo.txt"
43+
_ = ioutil.WriteFile(repoPath+"/"+untrackedMockFile, []byte{byte(63)}, 0755)
4644

4745
expectedResults := &model.GitChangeResults{
48-
GitUntrackedFiles: []*string{&untrackedResult},
49-
GitChangedFiles: []*string{&changedResult},
50-
GitStagedFiles: []*string{&stagedResult},
46+
GitUntrackedFiles: []*string{&untrackedMockFile},
47+
GitChangedFiles: []*string{&mockFile},
48+
GitStagedFiles: []*string{&mockFile},
5149
}
5250

5351
type args struct {
@@ -67,22 +65,25 @@ func TestChangedFiles(t *testing.T) {
6765
Repo: tt.args.repo,
6866
RepoPath: "",
6967
}
68+
7069
got := testObj.ChangedFiles()
7170

7271
stagedFile := *got.GitStagedFiles[0]
7372
untrackedFile := *got.GitUntrackedFiles[0]
7473
changedFile := *got.GitChangedFiles[0]
7574
changedFile = strings.Split(changedFile, ",")[1]
7675

77-
fmt.Println(stagedFile)
78-
fmt.Println(untrackedFile)
79-
fmt.Println(changedFile)
76+
assert.Equal(t, *tt.want.GitStagedFiles[0], stagedFile)
77+
assert.Equal(t, *tt.want.GitChangedFiles[0], changedFile)
78+
assert.Equal(t, *tt.want.GitUntrackedFiles[0], untrackedFile)
8079

81-
if stagedFile == *tt.want.GitStagedFiles[0] && untrackedFile == *tt.want.GitUntrackedFiles[0] && changedFile == *tt.want.GitChangedFiles[0] {
82-
fmt.Println("Test Passed")
83-
} else {
84-
t.Errorf("ChangedFiles() = %v, want %v", *got.GitStagedFiles[0], *tt.want.GitStagedFiles[0])
80+
reset := git2.ResetAllStruct{
81+
Repo: r,
8582
}
83+
reset.ResetAllItems()
84+
85+
fmt.Println(os.Remove(repoPath + "/" + mockFile))
86+
fmt.Println(os.Remove(repoPath + "/" + untrackedMockFile))
8687
})
8788
}
8889
}

tests/git_commit_changes_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ import (
44
"fmt"
55
git2go "github.com/libgit2/git2go/v31"
66
git2 "github.com/neel1996/gitconvex-server/git"
7+
"github.com/stretchr/testify/assert"
78
"io/ioutil"
89
"os"
10+
"path"
911
"testing"
1012
)
1113

1214
func TestCommitChanges(t *testing.T) {
1315
var repoPath string
1416
var r *git2go.Repository
17+
cwd, _ := os.Getwd()
18+
mockRepoPath := path.Join(cwd, "../..") + "/starfleet"
1519
currentEnv := os.Getenv("GOTESTENV")
1620
fmt.Println("Environment : " + currentEnv)
1721

1822
if currentEnv == "ci" {
19-
repoPath = "/home/runner/work/gitconvex-server/starfleet"
23+
repoPath = mockRepoPath
2024
r, _ = git2go.OpenRepository(repoPath)
2125
}
2226

@@ -52,9 +56,8 @@ func TestCommitChanges(t *testing.T) {
5256
RepoPath: repoPath,
5357
}
5458

55-
if got := testObj.CommitChanges(); got != tt.want {
56-
t.Errorf("CommitChanges() = %v, want %v", got, tt.want)
57-
}
59+
got := testObj.CommitChanges()
60+
assert.Equal(t, tt.want, got)
5861
})
5962
}
6063
}

0 commit comments

Comments
 (0)