@@ -6,88 +6,88 @@ import (
66 "testing"
77)
88
9- // func TestInitGitHubSettings(t *testing.T) {
10- // t.Run("github action pull request", func(t *testing.T) {
11- // // Set this vars if running locally, othersie just use the ones from the workflow
12- // if _, ok := os.LookupEnv("GITHUB_ACTIONS"); !ok {
13- // _ = os.Setenv("GITHUB_ACTIONS", "true")
14- // defer os.Unsetenv("GITHUB_ACTIONS")
15- // _ = os.Setenv("GITHUB_TOKEN", "foo")
16- // defer os.Unsetenv("GITHUB_TOKEN")
17- // _ = os.Setenv("GITHUB_REPOSITORY", "coolapso/convcommitlint")
18- // defer os.Unsetenv("GITHUB_REPOSITORY")
19- // defer func() { repository = "" }()
20- // _ = os.Setenv("GITHUB_REF_NAME", "25/merge")
21- // defer os.Unsetenv("GITHUB_REF_NAME")
22- // }
23- //
24- // var tempType string
25- // if v, ok := os.LookupEnv("GITHUB_EVENT_NAME"); ok {
26- // if v != "pull_request" {
27- // tempType = v
28- // os.Setenv("GITHUB_EVENT_NAME", "pull_request")
29- // defer os.Setenv("GITHUB_EVENT_NAME", tempType)
30- // }
31- // } else {
32- // _ = os.Setenv("GITHUB_EVENT_NAME", "pull_request")
33- // defer os.Unsetenv("GITHUB_EVENT_NAME")
34- // }
35- //
36- // got := initGHSettings()
37- // if got != nil {
38- // t.Fatal("Expected nil, got:", got)
39- // }
40- // })
41- //
42- // t.Run("github action push", func(t *testing.T) {
43- // if _, ok := os.LookupEnv("GITHUB_ACTIONS"); !ok {
44- // _ = os.Setenv("GITHUB_ACTIONS", "true")
45- // defer os.Unsetenv("GITHUB_ACTIONS")
46- // _ = os.Setenv("GITHUB_TOKEN", "foo")
47- // defer os.Unsetenv("GITHUB_REPOSITORY")
48- // _ = os.Setenv("GITHUB_REPOSITORY", "coolapso/convcommitlint")
49- // defer os.Unsetenv("GITHUB_TOKEN")
50- // defer func() { repository = "" }()
51- // }
52- //
53- // var eventTemp string
54- // if v, ok := os.LookupEnv("GITHUB_EVENT_NAME"); ok {
55- // eventTemp = v
56- // os.Setenv("GITHUB_EVENT_NAME", "push")
57- // defer os.Setenv("GITHUB_EVENT_NAME", eventTemp)
58- // } else {
59- // os.Setenv("GITHUB_EVENT_NAME", "push")
60- // defer os.Setenv("GITHUB_EVENT_NAME", eventTemp)
61- // }
62- //
63- // got := initGHSettings()
64- // if got != nil {
65- // t.Fatal("Expected nil, got:", got)
66- // }
67- // })
68- //
69- // t.Run("missing github repository", func(t *testing.T) {
70- // got := initGHSettings()
71- // if got != errMissingRepository {
72- // t.Fatalf("Expected [ %v ] error, got [ %v ]", errMissingRepository, got)
73- // }
74- // })
75- //
76- // t.Run("Run locally", func(t *testing.T) {
77- // if _, ok := os.LookupEnv("GITHUB_ACTIONS"); !ok {
78- // _ = os.Setenv("GITHUB_TOKEN", "foo")
79- // defer os.Unsetenv("GITHUB_TOKEN")
80- // _ = os.Setenv("GITHUB_REPOSITORY", "coolapso/convcommitlint")
81- // defer os.Unsetenv("GITHUB_REPOSITORY")
82- // func() { repository = "" }()
83- // }
84- // prNumber = 25
85- // got := initGHSettings()
86- // if got != nil {
87- // t.Fatal("Expected nil, got:", got)
88- // }
89- // })
90- // }
9+ func TestInitGitHubSettings (t * testing.T ) {
10+ t .Run ("github action pull request" , func (t * testing.T ) {
11+ // Set this vars if running locally, othersie just use the ones from the workflow
12+ if _ , ok := os .LookupEnv ("GITHUB_ACTIONS" ); ! ok {
13+ _ = os .Setenv ("GITHUB_ACTIONS" , "true" )
14+ defer os .Unsetenv ("GITHUB_ACTIONS" )
15+ _ = os .Setenv ("GITHUB_TOKEN" , "foo" )
16+ defer os .Unsetenv ("GITHUB_TOKEN" )
17+ _ = os .Setenv ("GITHUB_REPOSITORY" , "coolapso/convcommitlint" )
18+ defer os .Unsetenv ("GITHUB_REPOSITORY" )
19+ defer func () { repository = "" }()
20+ _ = os .Setenv ("GITHUB_REF_NAME" , "25/merge" )
21+ defer os .Unsetenv ("GITHUB_REF_NAME" )
22+ }
23+
24+ var tempType string
25+ if v , ok := os .LookupEnv ("GITHUB_EVENT_NAME" ); ok {
26+ if v != "pull_request" {
27+ tempType = v
28+ os .Setenv ("GITHUB_EVENT_NAME" , "pull_request" )
29+ defer os .Setenv ("GITHUB_EVENT_NAME" , tempType )
30+ }
31+ } else {
32+ _ = os .Setenv ("GITHUB_EVENT_NAME" , "pull_request" )
33+ defer os .Unsetenv ("GITHUB_EVENT_NAME" )
34+ }
35+
36+ got := initGHSettings ()
37+ if got != nil {
38+ t .Fatal ("Expected nil, got:" , got )
39+ }
40+ })
41+
42+ t .Run ("github action push" , func (t * testing.T ) {
43+ if _ , ok := os .LookupEnv ("GITHUB_ACTIONS" ); ! ok {
44+ _ = os .Setenv ("GITHUB_ACTIONS" , "true" )
45+ defer os .Unsetenv ("GITHUB_ACTIONS" )
46+ _ = os .Setenv ("GITHUB_TOKEN" , "foo" )
47+ defer os .Unsetenv ("GITHUB_REPOSITORY" )
48+ _ = os .Setenv ("GITHUB_REPOSITORY" , "coolapso/convcommitlint" )
49+ defer os .Unsetenv ("GITHUB_TOKEN" )
50+ defer func () { repository = "" }()
51+ }
52+
53+ var eventTemp string
54+ if v , ok := os .LookupEnv ("GITHUB_EVENT_NAME" ); ok {
55+ eventTemp = v
56+ os .Setenv ("GITHUB_EVENT_NAME" , "push" )
57+ defer os .Setenv ("GITHUB_EVENT_NAME" , eventTemp )
58+ } else {
59+ os .Setenv ("GITHUB_EVENT_NAME" , "push" )
60+ defer os .Setenv ("GITHUB_EVENT_NAME" , eventTemp )
61+ }
62+
63+ got := initGHSettings ()
64+ if got != nil {
65+ t .Fatal ("Expected nil, got:" , got )
66+ }
67+ })
68+
69+ t .Run ("missing github repository" , func (t * testing.T ) {
70+ got := initGHSettings ()
71+ if got != errMissingRepository {
72+ t .Fatalf ("Expected [ %v ] error, got [ %v ]" , errMissingRepository , got )
73+ }
74+ })
75+
76+ t .Run ("Run locally" , func (t * testing.T ) {
77+ if _ , ok := os .LookupEnv ("GITHUB_ACTIONS" ); ! ok {
78+ _ = os .Setenv ("GITHUB_TOKEN" , "foo" )
79+ defer os .Unsetenv ("GITHUB_TOKEN" )
80+ _ = os .Setenv ("GITHUB_REPOSITORY" , "coolapso/convcommitlint" )
81+ defer os .Unsetenv ("GITHUB_REPOSITORY" )
82+ func () { repository = "" }()
83+ }
84+ prNumber = 25
85+ got := initGHSettings ()
86+ if got != nil {
87+ t .Fatal ("Expected nil, got:" , got )
88+ }
89+ })
90+ }
9191
9292func TestGetGHToken (t * testing.T ) {
9393 t .Run ("missing token" , func (t * testing.T ) {
0 commit comments