Skip to content

Commit f324bac

Browse files
committed
Fixing linter errors
1 parent 9ea3bf2 commit f324bac

File tree

6 files changed

+36
-27
lines changed

6 files changed

+36
-27
lines changed

cmd/openapi_spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func newOpenapiSpecCmd() *cobra.Command {
7676
}
7777

7878
if outputFile != "" {
79-
if err := os.WriteFile(outputFile, []byte(spec), 0644); err != nil {
79+
if err := os.WriteFile(outputFile, []byte(spec), 0600); err != nil {
8080
return fmt.Errorf("failed to write output file: %w", err)
8181
}
8282
fmt.Fprintf(cmd.OutOrStdout(), "OpenAPI spec written to %s\n", outputFile)

cmd/openapi_spec_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
)
1515

1616
type mockClient struct {
17-
response []byte
1817
err error
18+
response []byte
1919
}
2020

2121
func (m *mockClient) SendRequest(req *http.Request) ([]byte, error) {
@@ -67,6 +67,15 @@ type fragment struct {
6767
Text string `json:"text"`
6868
}
6969

70+
type testCase struct {
71+
setupFiles map[string]string
72+
name string
73+
wantOutput string
74+
errContains string
75+
args []string
76+
wantErr bool
77+
}
78+
7079
func TestOpenapiSpecCmd(t *testing.T) {
7180
cleanup := setupTestConfig(t)
7281
defer cleanup()
@@ -90,15 +99,7 @@ func TestOpenapiSpecCmd(t *testing.T) {
9099
successRespBytes, err := json.Marshal(successResp)
91100
require.NoError(t, err)
92101

93-
tests := []struct {
94-
name string
95-
args []string
96-
input string
97-
setupFiles map[string]string
98-
wantErr bool
99-
errContains string
100-
wantOutput string
101-
}{
102+
tests := []testCase{
102103
{
103104
name: "no input provided",
104105
args: []string{},

glean

0 Bytes
Binary file not shown.

pkg/llm/openapi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
)
1111

1212
type chatRequest struct {
13-
Messages []message `json:"messages"`
14-
Stream bool `json:"stream"`
1513
AgentConfig struct {
1614
Agent string `json:"agent"`
1715
Mode string `json:"mode"`
1816
} `json:"agentConfig"`
17+
Messages []message `json:"messages"`
18+
Stream bool `json:"stream"`
1919
}
2020

2121
type message struct {

pkg/llm/openapi_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
)
1414

1515
type mockClient struct {
16-
response []byte
1716
err error
17+
response []byte
1818
}
1919

2020
func (m *mockClient) SendRequest(req *gleanhttp.Request) ([]byte, error) {
@@ -62,6 +62,18 @@ func setupTestConfig(t *testing.T) func() {
6262
}
6363
}
6464

65+
//nolint:govet // Ignoring fieldalignment as it's just an optimization
66+
type testCase struct {
67+
mockResp []byte
68+
mockErr error
69+
name string
70+
input string
71+
prompt string
72+
model string
73+
errContains string
74+
wantErr bool
75+
}
76+
6577
func TestGenerateOpenAPISpec(t *testing.T) {
6678
cleanup := setupTestConfig(t)
6779
defer cleanup()
@@ -85,16 +97,7 @@ func TestGenerateOpenAPISpec(t *testing.T) {
8597
successRespBytes, err := json.Marshal(successResp)
8698
require.NoError(t, err)
8799

88-
tests := []struct {
89-
name string
90-
input string
91-
prompt string
92-
model string
93-
mockResp []byte
94-
mockErr error
95-
wantErr bool
96-
errContains string
97-
}{
100+
tests := []testCase{
98101
{
99102
name: "empty input",
100103
input: "",

pkg/output/output.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ import (
1515
"golang.org/x/term"
1616
)
1717

18+
const (
19+
FormatJSON = "json"
20+
FormatYAML = "yaml"
21+
)
22+
1823
// Options represents configuration for output formatting
1924
type Options struct {
25+
Format string
2026
NoColor bool
21-
Format string // json, yaml, etc.
2227
}
2328

2429
// Write formats and writes the content to the writer with optional syntax highlighting
@@ -41,7 +46,7 @@ func shouldColorize(opts Options) bool {
4146

4247
func writeRaw(w io.Writer, content []byte, format string) error {
4348
switch format {
44-
case "json":
49+
case FormatJSON:
4550
var prettyJSON bytes.Buffer
4651
if err := json.Indent(&prettyJSON, content, "", " "); err != nil {
4752
return fmt.Errorf("failed to format JSON: %w", err)
@@ -57,7 +62,7 @@ func writeRaw(w io.Writer, content []byte, format string) error {
5762
func writeColorized(w io.Writer, content []byte, format string) error {
5863
var lexer chroma.Lexer
5964
switch format {
60-
case "json":
65+
case FormatJSON:
6166
lexer = lexers.Get("json")
6267
case "yaml":
6368
lexer = lexers.Get("yaml")

0 commit comments

Comments
 (0)