Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #155

Merged
merged 12 commits into from
Jun 11, 2024
8 changes: 4 additions & 4 deletions .github/workflows/codetests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ jobs:
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: 'v1.54'
version: 'v1.57'
# Runs golangci-lint on linux against linux and windows.
golangci-linux:
strategy:
Expand All @@ -65,6 +65,6 @@ jobs:
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: 'v1.54'
version: 'v1.57'
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# Exclude funlen for testing files.
- linters:
Expand Down Expand Up @@ -36,11 +38,15 @@ linters:
- nlreturn
- tagalign
- depguard
- musttag
- perfsprint # need to fix these
- testifylint # fix these too

# One day we'll fix all the field alignments. Anyone got a tool that just does it?
#linters-settings:
# govet:
# enable:
# - fieldalignment

run:
timeout: 5m
timeout: 5m
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module golift.io/starr

go 1.17
go 1.20

require golang.org/x/net v0.22.0 // publicsuffix, cookiejar.

Expand Down
3 changes: 2 additions & 1 deletion http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golift.io/starr"
)

Expand Down Expand Up @@ -39,7 +40,7 @@ func TestReqError(t *testing.T) {
t.Parallel()

err := &starr.ReqError{Code: http.StatusForbidden}
assert.ErrorIs(t, err, starr.ErrInvalidStatusCode)
require.ErrorIs(t, err, starr.ErrInvalidStatusCode)
assert.Equal(t, "invalid status code, 403 >= 300", err.Error())

err.Body = []byte("Some Body")
Expand Down
13 changes: 8 additions & 5 deletions lidarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,26 @@ func (l *Lidarr) GetDownloadClientContext(ctx context.Context, downloadclientID
return &output, nil
}

// AddDownloadClient creates a download client.
// AddDownloadClient creates a download client without testing it.
func (l *Lidarr) AddDownloadClient(downloadclient *DownloadClientInput) (*DownloadClientOutput, error) {
return l.AddDownloadClientContext(context.Background(), downloadclient)
}

// AddDownloadClientContext creates a download client.
// AddDownloadClientContext creates a download client without testing it.
func (l *Lidarr) AddDownloadClientContext(ctx context.Context,
client *DownloadClientInput,
) (*DownloadClientOutput, error) {
var output DownloadClientOutput
var (
output DownloadClientOutput
body bytes.Buffer
)

var body bytes.Buffer
client.ID = 0
if err := json.NewEncoder(&body).Encode(client); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClient, err)
}

req := starr.Request{URI: bpDownloadClient, Body: &body}
req := starr.Request{URI: bpDownloadClient, Body: &body, Query: url.Values{"forceSave": []string{"true"}}}
if err := l.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}
Expand Down
4 changes: 2 additions & 2 deletions lidarr/downloadclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestAddDownloadClient(t *testing.T) {
tests := []*starrtest.MockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "downloadClient"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "downloadClient?forceSave=true"),
ExpectedMethod: "POST",
ResponseStatus: 200,
WithRequest: &lidarr.DownloadClientInput{
Expand Down Expand Up @@ -297,7 +297,7 @@ func TestAddDownloadClient(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "downloadClient"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "downloadClient?forceSave=true"),
ExpectedMethod: "POST",
ResponseStatus: 404,
WithRequest: &lidarr.DownloadClientInput{
Expand Down
24 changes: 24 additions & 0 deletions lidarr/exclusions.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,27 @@ func (l *Lidarr) DeleteExclusionsContext(ctx context.Context, ids []int64) error

return nil
}

// AddExclusion adds one exclusion to Lidarr.
func (l *Lidarr) AddExclusion(exclusion *Exclusion) (*Exclusion, error) {
return l.AddExclusionContext(context.Background(), exclusion)
}

// AddExclusionContext adds one exclusion to Lidarr.
func (l *Lidarr) AddExclusionContext(ctx context.Context, exclusion *Exclusion) (*Exclusion, error) {
exclusion.ID = 0 // if this panics, fix your code

var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(exclusion); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpExclusions, err)
}

var output Exclusion

req := starr.Request{URI: path.Join(bpExclusions), Body: &body}
if err := l.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}

return &output, nil
}
13 changes: 8 additions & 5 deletions lidarr/importlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@ func (l *Lidarr) GetImportListContext(ctx context.Context, importListID int64) (
return &output, nil
}

// AddImportList creates a import list.
// AddImportList creates an import list without testing it.
func (l *Lidarr) AddImportList(importList *ImportListInput) (*ImportListOutput, error) {
return l.AddImportListContext(context.Background(), importList)
}

// AddImportListContext creates a import list.
// AddImportListContext creates an import list without testing it.
func (l *Lidarr) AddImportListContext(ctx context.Context, importList *ImportListInput) (*ImportListOutput, error) {
var output ImportListOutput
var (
output ImportListOutput
body bytes.Buffer
)

var body bytes.Buffer
importList.ID = 0
if err := json.NewEncoder(&body).Encode(importList); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpImportList, err)
}

req := starr.Request{URI: bpImportList, Body: &body}
req := starr.Request{URI: bpImportList, Body: &body, Query: url.Values{"forceSave": []string{"true"}}}
if err := l.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}
Expand Down
15 changes: 9 additions & 6 deletions lidarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (l *Lidarr) TestIndexerContext(ctx context.Context, indexer *IndexerInput)
return nil
}

// GetIndGetIndexerContextexer returns a single indexer.
// GetIndexerContext returns a single indexer.
func (l *Lidarr) GetIndexerContext(ctx context.Context, indexerID int64) (*IndexerOutput, error) {
var output IndexerOutput

Expand All @@ -103,21 +103,24 @@ func (l *Lidarr) GetIndexerContext(ctx context.Context, indexerID int64) (*Index
return &output, nil
}

// AddIndexer creates a indexer.
// AddIndexer creates an indexer without testing it.
func (l *Lidarr) AddIndexer(indexer *IndexerInput) (*IndexerOutput, error) {
return l.AddIndexerContext(context.Background(), indexer)
}

// AddIndexerContext creates a indexer.
// AddIndexerContext creates an indexer without testing it.
func (l *Lidarr) AddIndexerContext(ctx context.Context, indexer *IndexerInput) (*IndexerOutput, error) {
var output IndexerOutput
var (
output IndexerOutput
body bytes.Buffer
)

var body bytes.Buffer
indexer.ID = 0
if err := json.NewEncoder(&body).Encode(indexer); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpIndexer, err)
}

req := starr.Request{URI: bpIndexer, Body: &body}
req := starr.Request{URI: bpIndexer, Body: &body, Query: url.Values{"forceSave": []string{"true"}}}
if err := l.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}
Expand Down
4 changes: 2 additions & 2 deletions lidarr/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestAddIndexer(t *testing.T) {
tests := []*starrtest.MockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "indexer"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "indexer?forceSave=true"),
ExpectedMethod: "POST",
ResponseStatus: 200,
WithRequest: &lidarr.IndexerInput{
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestAddIndexer(t *testing.T) {
},
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "indexer"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "indexer?forceSave=true"),
ExpectedMethod: "POST",
ResponseStatus: 404,
WithRequest: &lidarr.IndexerInput{
Expand Down
3 changes: 2 additions & 1 deletion lidarr/indexerconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golift.io/starr"
"golift.io/starr/lidarr"
"golift.io/starr/starrtest"
Expand Down Expand Up @@ -115,7 +116,7 @@ func TestUpdateIndexerConfig(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.UpdateIndexerConfig(test.WithRequest.(*lidarr.IndexerConfig))
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
})
}
Expand Down
11 changes: 6 additions & 5 deletions lidarr/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golift.io/starr"
"golift.io/starr/lidarr"
"golift.io/starr/starrtest"
Expand Down Expand Up @@ -141,7 +142,7 @@ func TestGetNotifications(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetNotifications()
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -217,7 +218,7 @@ func TestGetNotification(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetNotification(1)
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -317,7 +318,7 @@ func TestAddNotification(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.AddNotification(test.WithRequest.(*lidarr.NotificationInput))
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -419,7 +420,7 @@ func TestUpdateNotification(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.UpdateNotification(test.WithRequest.(*lidarr.NotificationInput))
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -456,7 +457,7 @@ func TestDeleteNotification(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
err := client.DeleteNotification(test.WithRequest.(int64))
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
})
}
}
9 changes: 6 additions & 3 deletions lidarr/qualityprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ func (l *Lidarr) AddQualityProfile(profile *QualityProfile) (int64, error) {

// AddQualityProfileContext updates a quality profile in place.
func (l *Lidarr) AddQualityProfileContext(ctx context.Context, profile *QualityProfile) (int64, error) {
var body bytes.Buffer
var (
output QualityProfile
body bytes.Buffer
)

profile.ID = 0
if err := json.NewEncoder(&body).Encode(profile); err != nil {
return 0, fmt.Errorf("json.Marshal(%s): %w", bpQualityProfile, err)
}

var output QualityProfile

req := starr.Request{URI: bpQualityProfile, Body: &body}
if err := l.PostInto(ctx, req, &output); err != nil {
return 0, fmt.Errorf("api.Post(%s): %w", &req, err)
Expand Down
13 changes: 8 additions & 5 deletions prowlarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,26 @@ func (p *Prowlarr) GetDownloadClientContext(ctx context.Context, clientID int64)
return &output, nil
}

// AddDownloadClient creates a download client.
// AddDownloadClient creates a download client without testing it.
func (p *Prowlarr) AddDownloadClient(downloadclient *DownloadClientInput) (*DownloadClientOutput, error) {
return p.AddDownloadClientContext(context.Background(), downloadclient)
}

// AddDownloadClientContext creates a download client.
// AddDownloadClientContext creates a download client without testing it.
func (p *Prowlarr) AddDownloadClientContext(ctx context.Context,
client *DownloadClientInput,
) (*DownloadClientOutput, error) {
var output DownloadClientOutput
var (
output DownloadClientOutput
body bytes.Buffer
)

var body bytes.Buffer
client.ID = 0
if err := json.NewEncoder(&body).Encode(client); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClient, err)
}

req := starr.Request{URI: bpDownloadClient, Body: &body}
req := starr.Request{URI: bpDownloadClient, Body: &body, Query: url.Values{"forceSave": []string{"true"}}}
if err := p.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}
Expand Down
4 changes: 2 additions & 2 deletions prowlarr/downloadclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestAddDownloadClient(t *testing.T) {
tests := []*starrtest.MockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "downloadClient"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "downloadClient?forceSave=true"),
ExpectedMethod: "POST",
ResponseStatus: 200,
WithRequest: &prowlarr.DownloadClientInput{
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestAddDownloadClient(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "downloadClient"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "downloadClient?forceSave=true"),
ExpectedMethod: "POST",
ResponseStatus: 404,
WithRequest: &prowlarr.DownloadClientInput{
Expand Down
Loading
Loading