Skip to content

Commit 7c9d574

Browse files
committed
Adding additional tests to increase coverage. Cleanup of tasks in taskfile.yml
1 parent 8a39829 commit 7c9d574

File tree

10 files changed

+959
-166
lines changed

10 files changed

+959
-166
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ issues:
3131
linters:
3232
- gosec
3333
- errcheck
34+
- path: _test\.go
35+
text: "fieldalignment:"
3436
max-issues-per-linter: 0
3537
max-same-issues: 0
3638

RELEASE.md

Lines changed: 30 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,50 @@
11
# Release Process
22

3-
This document outlines the process for creating new releases of the Glean CLI.
3+
## Setup
44

5-
## Versioning
5+
After cloning the repository, run the following command to install required dependencies:
66

7-
We follow [Semantic Versioning](https://semver.org/) (SemVer):
8-
- MAJOR version (X.0.0) - incompatible API changes
9-
- MINOR version (0.X.0) - add functionality in a backward compatible manner
10-
- PATCH version (0.0.X) - backward compatible bug fixes
11-
12-
## Prerequisites
13-
14-
Install the required tools:
157
```bash
16-
# Install svu for automated versioning
17-
go install github.com/caarlos0/svu@latest
8+
task setup
189
```
1910

20-
## Release Steps
21-
22-
You can create a new release using either the automated task or the manual steps below.
23-
24-
### Automated Release
25-
26-
```bash
27-
# This will run all checks, create and push the tag
28-
task release
29-
```
30-
31-
### Manual Steps
32-
33-
If you need more control over the release process, you can follow these steps manually:
11+
This will install:
12+
- `svu` - for semantic versioning and tag management
13+
- `gotestsum` - for improved test output and summaries
14+
- `golangci-lint` - for code linting
3415

35-
1. **Ensure Main Branch is Ready**
36-
```bash
37-
git checkout main
38-
git pull origin main
39-
```
16+
## Creating a Release
4017

41-
2. **Run Tests and Checks**
42-
```bash
43-
task test
44-
task lint
45-
```
18+
To create a new release:
4619

47-
3. **Create Release**
20+
1. Ensure your working directory is clean and you're on the `main` branch
21+
2. Run the release task:
4822
```bash
49-
# Preview the next version based on conventional commits
50-
svu next
51-
52-
# Create and push the tag with the next version
53-
git tag -a $(svu next) -m "Release $(svu next)"
54-
git push origin $(svu next)
23+
task release
5524
```
5625

57-
Note: `svu` automatically determines the next version based on your commit messages:
58-
- `feat:` -> MINOR version bump
59-
- `fix:` -> PATCH version bump
60-
- `BREAKING CHANGE:` in commit body -> MAJOR version bump
61-
62-
4. **Monitor Release Process**
63-
- The GitHub Action will automatically:
64-
- Create a GitHub release
65-
- Build binaries for all supported platforms
66-
- Generate release notes from commits
67-
- Upload artifacts to the release
68-
- Update the Homebrew formula
69-
70-
5. **Verify Release**
71-
- Check the [GitHub releases page](https://github.com/scalvert/glean-cli/releases)
72-
- Verify Homebrew formula was updated
73-
- Test installation methods:
74-
```bash
75-
# Homebrew
76-
brew update
77-
brew install scalvert/tap/glean-cli
78-
79-
# Go Install
80-
go install github.com/scalvert/glean-cli@latest
81-
82-
# Shell Script
83-
curl -fsSL https://raw.githubusercontent.com/scalvert/glean-cli/main/install.sh | sh
84-
```
26+
This will:
27+
- Run all checks (lint, test, build)
28+
- Show the current version and commits since last release
29+
- Calculate and propose the next version
30+
- Create and push a git tag
31+
- Trigger the release workflow
8532

86-
## Release Artifacts
33+
### Optional Parameters
8734

88-
Each release includes:
89-
- Binary distributions for:
90-
- macOS (x86_64, arm64)
91-
- Linux (x86_64, arm64)
92-
- Windows (x86_64, arm64)
93-
- Source code (zip, tar.gz)
94-
- Checksums file
95-
- Changelog
96-
97-
## Commit Convention
98-
99-
To make the most of automated versioning, follow these commit message conventions:
100-
101-
```
102-
<type>: <description>
103-
104-
[optional body]
105-
106-
[optional footer(s)]
107-
```
108-
109-
Types:
110-
- `feat:` - New feature (MINOR version bump)
111-
- `fix:` - Bug fix (PATCH version bump)
112-
- `docs:` - Documentation only changes
113-
- `style:` - Changes that do not affect the meaning of the code
114-
- `refactor:` - Code change that neither fixes a bug nor adds a feature
115-
- `perf:` - Code change that improves performance
116-
- `test:` - Adding missing tests or correcting existing tests
117-
- `chore:` - Changes to the build process or auxiliary tools
118-
119-
Breaking Changes:
120-
- Add `BREAKING CHANGE:` to the commit body to trigger a MAJOR version bump
121-
- Example:
35+
- Specify a version:
36+
```bash
37+
task release VERSION=v1.2.3
12238
```
123-
feat: change API endpoint structure
12439

125-
BREAKING CHANGE: The API endpoint structure has changed from /v1/* to /api/v1/*
40+
- Force update an existing tag:
41+
```bash
42+
task release VERSION=v1.2.3 FORCE=true
12643
```
12744

128-
## Troubleshooting
129-
130-
1. **GitHub Action Failed**
131-
- Check the Action logs for errors
132-
- Ensure GITHUB_TOKEN has required permissions
133-
- Verify the tag follows the format `v*` (e.g., v1.0.0)
134-
135-
2. **Homebrew Update Failed**
136-
- Check if homebrew-tap repository exists
137-
- Verify repository permissions
138-
- Check the "Update Homebrew tap" step in the Action logs
139-
140-
3. **Bad Release**
141-
If a release has issues:
142-
```bash
143-
# Get current version
144-
current_version=$(svu current)
145-
146-
# Delete tag locally
147-
git tag -d $current_version
148-
149-
# Delete tag remotely
150-
git push --delete origin $current_version
151-
```
152-
Then fix the issues and retry the release process.
153-
154-
## Notes
45+
## Monitoring
15546

156-
- Release notes are automatically generated from commit messages
157-
- Commits starting with `docs:`, `test:`, `ci:` are excluded from release notes
158-
- The release process is automated via GitHub Actions
159-
- Binary distributions are built using GoReleaser
160-
- All releases are automatically published to GitHub Releases
47+
After creating a release:
48+
1. The GitHub Actions workflow will be triggered automatically
49+
2. Monitor the release at: https://github.com/scalvert/glean-cli/actions
50+
3. Once complete, the release will be available at: https://github.com/scalvert/glean-cli/releases

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ go 1.20
44

55
require (
66
github.com/MakeNowJust/heredoc v1.0.0
7+
github.com/alecthomas/chroma v0.10.0
78
github.com/briandowns/spinner v1.23.2
9+
github.com/mattn/go-tty v0.0.7
810
github.com/spf13/cobra v1.8.1
911
github.com/stretchr/testify v1.10.0
1012
github.com/zalando/go-keyring v0.2.3
1113
golang.org/x/term v0.28.0
12-
gopkg.in/validator.v2 v2.0.1
1314
)
1415

1516
require (
16-
github.com/alecthomas/chroma v0.10.0 // indirect
1717
github.com/alessio/shellescape v1.4.1 // indirect
1818
github.com/danieljoos/wincred v1.2.0 // indirect
1919
github.com/davecgh/go-spew v1.1.1 // indirect
2020
github.com/dlclark/regexp2 v1.4.0 // indirect
21-
github.com/fatih/color v1.7.0 // indirect
21+
github.com/fatih/color v1.16.0 // indirect
2222
github.com/godbus/dbus/v5 v5.1.0 // indirect
2323
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2424
github.com/mattn/go-colorable v0.1.13 // indirect
2525
github.com/mattn/go-isatty v0.0.20 // indirect
26-
github.com/mattn/go-tty v0.0.7 // indirect
2726
github.com/pmezard/go-difflib v1.0.0 // indirect
2827
github.com/spf13/pflag v1.0.5 // indirect
2928
golang.org/x/sys v0.29.0 // indirect
29+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
3030
gopkg.in/yaml.v3 v3.0.1 // indirect
3131
)

go.sum

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1414
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1515
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
1616
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
17-
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
18-
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
17+
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
18+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
1919
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
2020
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
2121
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
2222
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
2323
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
24+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
25+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2426
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
25-
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
26-
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
27+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2728
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2829
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
29-
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
30-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
3130
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
3231
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
3332
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
@@ -47,7 +46,6 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
4746
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4847
github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms=
4948
github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk=
50-
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5149
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5250
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5351
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
@@ -56,8 +54,7 @@ golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
5654
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
5755
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5856
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
59-
gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY=
60-
gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8=
57+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
6158
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6259
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
6360
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/config/config_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package config
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestValidateAndTransformHost(t *testing.T) {
13+
tests := []struct {
14+
name string
15+
input string
16+
want string
17+
wantErr bool
18+
errContains string
19+
}{
20+
{
21+
name: "simple instance name",
22+
input: "linkedin",
23+
want: "linkedin-be.glean.com",
24+
},
25+
{
26+
name: "full valid hostname",
27+
input: "linkedin-be.glean.com",
28+
want: "linkedin-be.glean.com",
29+
},
30+
{
31+
name: "invalid domain",
32+
input: "linkedin.example.com",
33+
wantErr: true,
34+
errContains: "invalid host format",
35+
},
36+
{
37+
name: "missing -be suffix",
38+
input: "linkedin.glean.com",
39+
wantErr: true,
40+
errContains: "invalid host format",
41+
},
42+
}
43+
44+
for _, tt := range tests {
45+
t.Run(tt.name, func(t *testing.T) {
46+
got, err := ValidateAndTransformHost(tt.input)
47+
if tt.wantErr {
48+
assert.Error(t, err)
49+
if tt.errContains != "" {
50+
assert.Contains(t, err.Error(), tt.errContains)
51+
}
52+
} else {
53+
assert.NoError(t, err)
54+
assert.Equal(t, tt.want, got)
55+
}
56+
})
57+
}
58+
}
59+
60+
func TestConfigPath(t *testing.T) {
61+
t.Run("default config path", func(t *testing.T) {
62+
homeDir, err := os.UserHomeDir()
63+
require.NoError(t, err)
64+
expected := filepath.Join(homeDir, ".glean", "config.json")
65+
assert.Equal(t, expected, ConfigPath)
66+
})
67+
}
68+
69+
func TestConfigOperations(t *testing.T) {
70+
// Create a temporary directory for the keyring
71+
tmpDir := t.TempDir()
72+
t.Setenv("XDG_DATA_HOME", tmpDir)
73+
74+
t.Run("save and load config", func(t *testing.T) {
75+
// Save config
76+
err := SaveConfig("linkedin", "test-token", "test@example.com")
77+
require.NoError(t, err)
78+
79+
// Load config
80+
cfg, err := LoadConfig()
81+
require.NoError(t, err)
82+
83+
assert.Equal(t, "linkedin-be.glean.com", cfg.GleanHost)
84+
assert.Equal(t, "test-token", cfg.GleanToken)
85+
assert.Equal(t, "test@example.com", cfg.GleanEmail)
86+
})
87+
88+
t.Run("clear config", func(t *testing.T) {
89+
// First save some config
90+
err := SaveConfig("linkedin", "test-token", "test@example.com")
91+
require.NoError(t, err)
92+
93+
// Clear config
94+
err = ClearConfig()
95+
require.NoError(t, err)
96+
97+
// Load config should return empty values
98+
cfg, err := LoadConfig()
99+
require.NoError(t, err)
100+
assert.Empty(t, cfg.GleanHost)
101+
assert.Empty(t, cfg.GleanToken)
102+
assert.Empty(t, cfg.GleanEmail)
103+
})
104+
105+
t.Run("save invalid host", func(t *testing.T) {
106+
err := SaveConfig("invalid.example.com", "", "")
107+
assert.Error(t, err)
108+
assert.Contains(t, err.Error(), "invalid host format")
109+
})
110+
}

0 commit comments

Comments
 (0)