-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_test.go
89 lines (64 loc) · 2.02 KB
/
github_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
85
86
87
88
89
/*
Copyright © 2024 Patrick Hermann [email protected]
*/
package cli
import (
"fmt"
"io/ioutil"
"log"
"os"
"testing"
"github.com/google/go-github/v62/github"
"github.com/stretchr/testify/assert"
)
func TestGetReferenceObject_WithExistingBranch(t *testing.T) {
token := os.Getenv("GITHUB_TOKEN")
if token == "" {
log.Fatal("UNAUTHORIZED: NO TOKEN PRESENT")
}
client = github.NewClient(nil).WithAuthToken(token)
// CALL GETREFERENCEOBJECT
GetReferenceObject(client, "stuttgart-things", "machineshop", "test", "main")
}
func TestReadFileToVar_WithValidFile(t *testing.T) {
// CREATE A TEMPORARY FILE
tmpfile, err := ioutil.TempFile("", "example")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name()) // clean up
// WRITE SOME DATA TO THE FILE
text := []byte("Hello, World!")
if _, err := tmpfile.Write(text); err != nil {
t.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
t.Fatal(err)
}
// CALL THE READFILETOVAR FUNCTION
content, err := ReadFileToVar(tmpfile.Name())
// ASSERT THAT THE RETURNED CONTENT IS THE SAME AS THE DATA WRITTEN TO THE FILE
assert.Equal(t, text, content)
// ASSERT THAT THE RETURNED ERROR IS NIL
assert.Nil(t, err)
}
func TestReadFileToVar_WithNonExistentFile(t *testing.T) {
// CALL THE READFILETOVAR FUNCTION WITH A NON-EXISTENT FILE PATH
content, err := ReadFileToVar("non_existent_file.txt")
// ASSERT THAT THE RETURNED CONTENT IS NIL
assert.Nil(t, content)
// ASSERT THAT THE RETURNED ERROR IS NOT NIL
assert.NotNil(t, err)
}
// func TestMergePullRequest(t *testing.T) {
// token := ""
// if token == "" {
// log.Fatal("UNAUTHORIZED: NO TOKEN PRESENT")
// }
// client = github.NewClient(nil).WithAuthToken(token)
// MergePullRequest(client, "stuttgart-things", "stuttgart-things", "merge", "merge", 241)
// }
func TestGetCommitInformationFromGithubRepo(t *testing.T) {
commitExists, commitInformation, err := GetCommitInformationFromGithubRepo("stuttgart-things", "kaeffken", "main", "latest")
fmt.Println(commitExists, commitInformation, err)
}