Skip to content

Commit 28b1582

Browse files
authored
🧪 Add tests (#34)
* ✅ Add tests * ⬆️ Bump to Golang v1.20 * 🎨 Format commands for tests
1 parent 33e0d09 commit 28b1582

18 files changed

+155
-41
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ jobs:
3535

3636
- run: go get -v -t -d ./...
3737

38+
- run: go test -v ./...
39+
3840
- run: go build -v .

cmd/actions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
var (
37-
actionsCmd = &cobra.Command{
37+
ActionsCmd = &cobra.Command{
3838
Use: "actions",
3939
Short: "Report on GitHub Actions",
4040
Long: "Report on GitHub Actions",
@@ -130,9 +130,9 @@ type (
130130
)
131131

132132
func init() {
133-
rootCmd.AddCommand(actionsCmd)
133+
RootCmd.AddCommand(ActionsCmd)
134134

135-
actionsCmd.Flags().BoolVar(&exclude, "exclude", false, "Exclude Github Actions authored by GitHub")
135+
ActionsCmd.Flags().BoolVar(&exclude, "exclude", false, "Exclude Github Actions authored by GitHub")
136136
}
137137

138138
// GetActionsReport returns a report on GitHub Actions

cmd/actions_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_Actions(t *testing.T) {
8+
t.Skip()
9+
}

cmd/billing.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
var (
36-
billingCmd = &cobra.Command{
36+
BillingCmd = &cobra.Command{
3737
Use: "billing",
3838
Short: "Report on GitHub billing",
3939
Long: "Report on GitHub billing",
@@ -50,18 +50,18 @@ var (
5050
)
5151

5252
func init() {
53-
billingCmd.PersistentFlags().BoolVar(&all, "all", true, "Get all billing data")
54-
billingCmd.PersistentFlags().BoolVar(&actions, "actions", false, "Get GitHub Actions billing")
55-
billingCmd.PersistentFlags().BoolVar(&packages, "packages", false, "Get GitHub Packages billing")
56-
billingCmd.PersistentFlags().BoolVar(&security, "security", false, "Get GitHub Advanced Security active committers")
57-
billingCmd.PersistentFlags().BoolVar(&storage, "storage", false, "Get shared storage billing")
58-
59-
billingCmd.MarkFlagsMutuallyExclusive("all", "actions")
60-
billingCmd.MarkFlagsMutuallyExclusive("all", "packages")
61-
billingCmd.MarkFlagsMutuallyExclusive("all", "security")
62-
billingCmd.MarkFlagsMutuallyExclusive("all", "storage")
63-
64-
rootCmd.AddCommand(billingCmd)
53+
BillingCmd.PersistentFlags().BoolVar(&all, "all", true, "Get all billing data")
54+
BillingCmd.PersistentFlags().BoolVar(&actions, "actions", false, "Get GitHub Actions billing")
55+
BillingCmd.PersistentFlags().BoolVar(&packages, "packages", false, "Get GitHub Packages billing")
56+
BillingCmd.PersistentFlags().BoolVar(&security, "security", false, "Get GitHub Advanced Security active committers")
57+
BillingCmd.PersistentFlags().BoolVar(&storage, "storage", false, "Get shared storage billing")
58+
59+
BillingCmd.MarkFlagsMutuallyExclusive("all", "actions")
60+
BillingCmd.MarkFlagsMutuallyExclusive("all", "packages")
61+
BillingCmd.MarkFlagsMutuallyExclusive("all", "security")
62+
BillingCmd.MarkFlagsMutuallyExclusive("all", "storage")
63+
64+
RootCmd.AddCommand(BillingCmd)
6565
}
6666

6767
type (

cmd/billing_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_Billing(t *testing.T) {
8+
t.Skip()
9+
}

cmd/license.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
var (
35-
licenseCmd = &cobra.Command{
35+
LicenseCmd = &cobra.Command{
3636
Use: "license",
3737
Short: "Report on GitHub Enterprise licensing",
3838
Long: "Report on GitHub Enterprise licensing",
@@ -44,7 +44,7 @@ var (
4444
)
4545

4646
func init() {
47-
rootCmd.AddCommand(licenseCmd)
47+
RootCmd.AddCommand(LicenseCmd)
4848
}
4949

5050
type (

cmd/license_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_License(t *testing.T) {
8+
t.Skip()
9+
}

cmd/repo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
private = false
3838
public = false
3939

40-
repoCmd = &cobra.Command{
40+
RepoCmd = &cobra.Command{
4141
Use: "repo",
4242
Short: "Report on GitHub repositories",
4343
Long: "Report on GitHub repositories",
@@ -107,11 +107,11 @@ type (
107107
)
108108

109109
func init() {
110-
rootCmd.AddCommand(repoCmd)
110+
RootCmd.AddCommand(RepoCmd)
111111

112-
repoCmd.Flags().BoolVar(&internal, "internal", false, "Show internal repositories only")
113-
repoCmd.Flags().BoolVar(&private, "private", false, "Show private repositories only")
114-
repoCmd.Flags().BoolVar(&public, "public", false, "Show public repositories only")
112+
RepoCmd.Flags().BoolVar(&internal, "internal", false, "Show internal repositories only")
113+
RepoCmd.Flags().BoolVar(&private, "private", false, "Show private repositories only")
114+
RepoCmd.Flags().BoolVar(&public, "public", false, "Show public repositories only")
115115
}
116116

117117
// GetUses returns GitHub Actions used in workflows

cmd/repo_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_Repo(t *testing.T) {
8+
t.Skip()
9+
}

cmd/root.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var (
6666

6767
sp = spinner.New(spinner.CharSets[14], 40*time.Millisecond)
6868

69-
rootCmd = &cobra.Command{
69+
RootCmd = &cobra.Command{
7070
Use: "gh-report",
7171
Short: "gh cli extension to generate reports",
7272
Long: `gh cli extension to generate enterprise/organization/user/repository reports`,
@@ -98,30 +98,30 @@ type (
9898
// Execute adds all child commands to the root command and sets flags appropriately.
9999
// This is called by main.main(). It only needs to happen once to the rootCmd.
100100
func Execute() {
101-
if err := rootCmd.Execute(); err != nil {
101+
if err := RootCmd.Execute(); err != nil {
102102
ExitOnError(err)
103103
}
104104
}
105105

106106
func init() {
107107
cobra.OnInitialize(initConfig)
108108

109-
rootCmd.PersistentFlags().BoolVar(&noCache, "no-cache", false, "do not cache results for one hour (default: false)")
110-
rootCmd.PersistentFlags().BoolVar(&silent, "silent", false, "do not print any output (default: false)")
109+
RootCmd.PersistentFlags().BoolVar(&noCache, "no-cache", false, "do not cache results for one hour (default: false)")
110+
RootCmd.PersistentFlags().BoolVar(&silent, "silent", false, "do not print any output (default: false)")
111111

112-
rootCmd.PersistentFlags().StringVarP(&enterprise, "enterprise", "e", "", "GitHub Enterprise Cloud account")
113-
rootCmd.PersistentFlags().StringVarP(&owner, "owner", "o", "", "GitHub account (organization or user account)")
114-
rootCmd.PersistentFlags().StringVarP(&repo, "repo", "r", "", "GitHub repository (owner/repo)")
112+
RootCmd.PersistentFlags().StringVarP(&enterprise, "enterprise", "e", "", "GitHub Enterprise Cloud account")
113+
RootCmd.PersistentFlags().StringVarP(&owner, "owner", "o", "", "GitHub account (organization or user account)")
114+
RootCmd.PersistentFlags().StringVarP(&repo, "repo", "r", "", "GitHub repository (owner/repo)")
115115

116-
rootCmd.PersistentFlags().StringVar(&token, "token", "", "GitHub Personal Access Token (default: gh auth token)")
117-
rootCmd.PersistentFlags().StringVar(&hostname, "hostname", "", "GitHub Enterprise Server hostname")
116+
RootCmd.PersistentFlags().StringVar(&token, "token", "", "GitHub Personal Access Token (default: gh auth token)")
117+
RootCmd.PersistentFlags().StringVar(&hostname, "hostname", "", "GitHub Enterprise Server hostname")
118118

119-
rootCmd.PersistentFlags().StringVar(&csvPath, "csv", "", "Path to CSV file")
120-
rootCmd.PersistentFlags().StringVar(&jsonPath, "json", "", "Path to JSON file")
119+
RootCmd.PersistentFlags().StringVar(&csvPath, "csv", "", "Path to CSV file")
120+
RootCmd.PersistentFlags().StringVar(&jsonPath, "json", "", "Path to JSON file")
121121

122-
rootCmd.MarkFlagsMutuallyExclusive("enterprise", "owner")
123-
rootCmd.MarkFlagsMutuallyExclusive("enterprise", "repo")
124-
rootCmd.MarkFlagsMutuallyExclusive("owner", "repo")
122+
RootCmd.MarkFlagsMutuallyExclusive("enterprise", "owner")
123+
RootCmd.MarkFlagsMutuallyExclusive("enterprise", "repo")
124+
RootCmd.MarkFlagsMutuallyExclusive("owner", "repo")
125125
}
126126

127127
func initConfig() {
@@ -179,7 +179,7 @@ func run(cmd *cobra.Command, args []string) (err error) {
179179

180180
func ExitOnError(err error) {
181181
if err != nil {
182-
rootCmd.PrintErrln(red(err.Error()))
182+
RootCmd.PrintErrln(red(err.Error()))
183183
os.Exit(1)
184184
}
185185
}

0 commit comments

Comments
 (0)