Skip to content

Commit

Permalink
use idiomatic module name
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerhardt committed Jul 19, 2024
1 parent e09deb4 commit 6428b54
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MOCKERY_CMD = mockery --name=Http --dir=./internal/client --output=./internal/client/mocks --outpkg=mocks
MOCKERY_CMD = mockery --name=HTTP --dir=./internal/client --output=./internal/client/mocks --outpkg=mocks
GOLANGCI_LINT := $(GOPATH)/bin/golangci-lint

.PHONY: mocks
Expand Down
4 changes: 2 additions & 2 deletions cmd/chatter/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"chatter/internal/client"
"chatter/internal/config"
"flag"
"github.com/joho/godotenv"
"github.com/sgerhardt/chatter/internal/client"
"github.com/sgerhardt/chatter/internal/config"
"log"
"net"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module chatter
module github.com/sgerhardt/chatter

go 1.22

Expand Down
2 changes: 1 addition & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package client

import (
"bytes"
"chatter/internal/config"
"encoding/json"
"fmt"
"github.com/sgerhardt/chatter/internal/config"
"io"
"log"
"net/http"
Expand Down
13 changes: 7 additions & 6 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package client

import (
"bytes"
"chatter/internal/client/mocks"
"chatter/internal/config"
"github.com/sgerhardt/chatter/internal/client/mocks"
"github.com/sgerhardt/chatter/internal/config"

"errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -30,7 +31,7 @@ func TestClient_GenerateVoiceFromText(t *testing.T) {
fields fields
args args
error error
mockSetup func(client *mocks.Http)
mockSetup func(client *mocks.HTTP)
}{
{
name: "errors if voice id is not populated",
Expand All @@ -39,7 +40,7 @@ func TestClient_GenerateVoiceFromText(t *testing.T) {
voiceID: "",
},
error: errors.New("voice ID is required"),
mockSetup: func(_ *mocks.Http) {},
mockSetup: func(_ *mocks.HTTP) {},
},
{
name: "marshals a payload to json",
Expand All @@ -49,7 +50,7 @@ func TestClient_GenerateVoiceFromText(t *testing.T) {
voiceID: "stephen_hawking",
},

mockSetup: func(client *mocks.Http) {
mockSetup: func(client *mocks.HTTP) {
mockResp := &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader([]byte("bytes representing the mp3 file..."))),
Expand All @@ -72,7 +73,7 @@ func TestClient_GenerateVoiceFromText(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
mockClient := mocks.NewHttp(t)
mockClient := mocks.NewHTTP(t)
tt.mockSetup(mockClient)
cfg := config.AppConfig{
CharacterRequestLimit: 100,
Expand Down
15 changes: 8 additions & 7 deletions internal/client/mocks/Http.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions internal/client/web_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package client

import (
"chatter/internal/client/mocks"
"chatter/internal/config"
"github.com/sgerhardt/chatter/internal/client/mocks"
"github.com/sgerhardt/chatter/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io"
Expand All @@ -20,13 +20,13 @@ func TestWebReader(t *testing.T) {

error error
charLimit int
mockSetup func(client *mocks.Http)
mockSetup func(client *mocks.HTTP)
}{
{
name: "Given a website, read the header and body",
want: []string{"This is the h1\nThis is paragraph text\n"},
charLimit: 100,
mockSetup: func(client *mocks.Http) {
mockSetup: func(client *mocks.HTTP) {
client.On("Do", mock.Anything).Return(&http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(`<html><body><h1>This is the h1</h1><p>This is paragraph text</p></body></html>`)),
Expand All @@ -37,7 +37,7 @@ func TestWebReader(t *testing.T) {
name: "Given a website that requires batching requests",
want: []string{"This ", "is th", "e h1\n", "This ", "is pa", "ragra", "ph te", "xt\n"},
charLimit: 5,
mockSetup: func(client *mocks.Http) {
mockSetup: func(client *mocks.HTTP) {
client.On("Do", mock.Anything).Return(&http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader(`<html><body><h1>This is the h1</h1><p>This is paragraph text</p></body></html>`)),
Expand All @@ -48,7 +48,7 @@ func TestWebReader(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
mockClient := mocks.NewHttp(t)
mockClient := mocks.NewHTTP(t)
tt.mockSetup(mockClient)
appConfig := config.AppConfig{
CharacterRequestLimit: tt.charLimit,
Expand Down

0 comments on commit 6428b54

Please sign in to comment.