github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/modules/scm/git_github_test.go (about) 1 // +build github 2 3 package scm 4 5 import ( 6 "context" 7 "os" 8 "testing" 9 10 "github.com/covergates/covergates/core" 11 "github.com/google/go-cmp/cmp" 12 ) 13 14 func TestGithubFindCommit(t *testing.T) { 15 service := &gitService{ 16 scm: core.Github, 17 scmClient: getGithubClient(), 18 } 19 ctx := context.Background() 20 user := &core.User{ 21 GithubToken: os.Getenv("GITHUB_SECRET"), 22 } 23 sha := service.FindCommit(ctx, user, &core.Repo{ 24 Name: "livelogs", 25 NameSpace: "blueworrybear", 26 Branch: "master", 27 }) 28 if sha == "" { 29 t.Fail() 30 } 31 } 32 33 func TestGitHubListBranch(t *testing.T) { 34 service := &gitService{ 35 scm: core.Github, 36 scmClient: getGithubClient(), 37 } 38 ctx := context.Background() 39 user := &core.User{ 40 GithubToken: os.Getenv("GITHUB_SECRET"), 41 } 42 branches, err := service.ListBranches(ctx, user, "blueworrybear/livelogs") 43 if err != nil { 44 t.Fatal(err) 45 } 46 if len(branches) < 1 { 47 t.Fatal() 48 } 49 } 50 51 func TestGithubListCommits(t *testing.T) { 52 service := &gitService{ 53 scm: core.Github, 54 scmClient: getGithubClient(), 55 } 56 user := &core.User{ 57 GithubToken: os.Getenv("GITHUB_SECRET"), 58 } 59 ctx := context.Background() 60 61 commits, err := service.ListCommitsByRef(ctx, user, "octocat/Hello-World", "test") 62 if err != nil { 63 t.Fatal(err) 64 } 65 if len(commits) <= 0 { 66 t.Fatal() 67 } 68 if diff := cmp.Diff("b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf", commits[0].Sha); diff != "" { 69 t.Fatal(diff) 70 } 71 }