From 5eb2efeef37f70d5566caf7fc56946097d6acf8c Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Tue, 29 Nov 2022 21:22:00 -0800 Subject: [PATCH 1/3] do not hard code moveFiles --- lidarr/album.go | 9 ++++----- readarr/book.go | 9 ++++----- sonarr/series.go | 10 ++++------ sonarr/series_test.go | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lidarr/album.go b/lidarr/album.go index 583a937..2928df9 100644 --- a/lidarr/album.go +++ b/lidarr/album.go @@ -156,7 +156,6 @@ func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *A Query: make(url.Values), Body: &body, } - req.Query.Add("moveFiles", "true") if err := l.PutInto(ctx, req, &output); err != nil { return nil, fmt.Errorf("api.Put(%s): %w", &req, err) @@ -166,12 +165,12 @@ func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *A } // AddAlbum adds a new album to Lidarr, and probably does not yet work. -func (l *Lidarr) AddAlbum(album *AddAlbumInput) (*Album, error) { - return l.AddAlbumContext(context.Background(), album) +func (l *Lidarr) AddAlbum(album *AddAlbumInput, moveFiles bool) (*Album, error) { + return l.AddAlbumContext(context.Background(), album, moveFiles) } // AddAlbumContext adds a new album to Lidarr, and probably does not yet work. -func (l *Lidarr) AddAlbumContext(ctx context.Context, album *AddAlbumInput) (*Album, error) { +func (l *Lidarr) AddAlbumContext(ctx context.Context, album *AddAlbumInput, moveFiles bool) (*Album, error) { if album.Releases == nil { album.Releases = make([]*AddAlbumInputRelease, 0) } @@ -186,7 +185,7 @@ func (l *Lidarr) AddAlbumContext(ctx context.Context, album *AddAlbumInput) (*Al Query: make(url.Values), Body: &body, } - req.Query.Add("moveFiles", "true") + req.Query.Add("moveFiles", fmt.Sprint(moveFiles)) var output Album if err := l.PostInto(ctx, req, &output); err != nil { diff --git a/readarr/book.go b/readarr/book.go index 3c06574..2e75eba 100644 --- a/readarr/book.go +++ b/readarr/book.go @@ -147,12 +147,12 @@ func (r *Readarr) GetBookByIDContext(ctx context.Context, bookID int64) (*Book, } // UpdateBook updates a book in place. -func (r *Readarr) UpdateBook(bookID int64, book *Book) error { - return r.UpdateBookContext(context.Background(), bookID, book) +func (r *Readarr) UpdateBook(bookID int64, book *Book, moveFiles bool) error { + return r.UpdateBookContext(context.Background(), bookID, book, moveFiles) } // UpdateBookContext updates a book in place. -func (r *Readarr) UpdateBookContext(ctx context.Context, bookID int64, book *Book) error { +func (r *Readarr) UpdateBookContext(ctx context.Context, bookID int64, book *Book, moveFiles bool) error { var body bytes.Buffer if err := json.NewEncoder(&body).Encode(book); err != nil { return fmt.Errorf("json.Marshal(%s): %w", bpBook, err) @@ -163,7 +163,7 @@ func (r *Readarr) UpdateBookContext(ctx context.Context, bookID int64, book *Boo Query: make(url.Values), Body: &body, } - req.Query.Add("moveFiles", "true") + req.Query.Add("moveFiles", fmt.Sprint(moveFiles)) var output interface{} // do not know what this looks like. @@ -191,7 +191,6 @@ func (r *Readarr) AddBookContext(ctx context.Context, book *AddBookInput) (*Book Query: make(url.Values), Body: &body, } - req.Query.Add("moveFiles", "true") var output Book if err := r.PostInto(ctx, req, &output); err != nil { diff --git a/sonarr/series.go b/sonarr/series.go index 005d1ed..0cb0685 100644 --- a/sonarr/series.go +++ b/sonarr/series.go @@ -145,12 +145,12 @@ func (s *Sonarr) GetSeriesContext(ctx context.Context, tvdbID int64) ([]*Series, } // UpdateSeries updates a series in place. -func (s *Sonarr) UpdateSeries(series *AddSeriesInput) (*Series, error) { - return s.UpdateSeriesContext(context.Background(), series) +func (s *Sonarr) UpdateSeries(series *AddSeriesInput, moveFiles bool) (*Series, error) { + return s.UpdateSeriesContext(context.Background(), series, moveFiles) } // UpdateSeriesContext updates a series in place. -func (s *Sonarr) UpdateSeriesContext(ctx context.Context, series *AddSeriesInput) (*Series, error) { +func (s *Sonarr) UpdateSeriesContext(ctx context.Context, series *AddSeriesInput, moveFiles bool) (*Series, error) { var body bytes.Buffer if err := json.NewEncoder(&body).Encode(series); err != nil { return nil, fmt.Errorf("json.Marshal(%s): %w", bpSeries, err) @@ -163,7 +163,7 @@ func (s *Sonarr) UpdateSeriesContext(ctx context.Context, series *AddSeriesInput Query: make(url.Values), Body: &body, } - req.Query.Add("moveFiles", "true") + req.Query.Add("moveFiles", fmt.Sprint(moveFiles)) if err := s.PutInto(ctx, req, &output); err != nil { return nil, fmt.Errorf("api.Put(%s): %w", &req, err) @@ -187,8 +187,6 @@ func (s *Sonarr) AddSeriesContext(ctx context.Context, series *AddSeriesInput) ( var output Series req := starr.Request{URI: bpSeries, Query: make(url.Values), Body: &body} - req.Query.Add("moveFiles", "true") - if err := s.PostInto(ctx, req, &output); err != nil { return nil, fmt.Errorf("api.Post(%s): %w", &req, err) } diff --git a/sonarr/series_test.go b/sonarr/series_test.go index 669f348..fff3398 100644 --- a/sonarr/series_test.go +++ b/sonarr/series_test.go @@ -1205,7 +1205,7 @@ func TestUpdateSeries(t *testing.T) { t.Parallel() mockServer := test.GetMockServer(t) client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0)) - output, err := client.UpdateSeries(test.WithRequest.(*sonarr.AddSeriesInput)) + output, err := client.UpdateSeries(test.WithRequest.(*sonarr.AddSeriesInput), false) assert.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") }) From a2635ade9a1957a5dcf48df8bb3bd00042c1affd Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 30 Nov 2022 18:42:31 -0800 Subject: [PATCH 2/3] fix test --- sonarr/series_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sonarr/series_test.go b/sonarr/series_test.go index fff3398..8201fb4 100644 --- a/sonarr/series_test.go +++ b/sonarr/series_test.go @@ -821,7 +821,7 @@ func TestAddSeries(t *testing.T) { tests := []*starr.TestMockData{ { Name: "200", - ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series?moveFiles=true"), + ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series"), ExpectedMethod: "POST", ExpectedRequest: addSeries, ResponseStatus: 200, @@ -965,7 +965,7 @@ func TestAddSeries(t *testing.T) { }, { Name: "404", - ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series?moveFiles=true"), + ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series"), ExpectedMethod: "POST", ExpectedRequest: addSeries, ResponseStatus: 404, @@ -1038,7 +1038,7 @@ func TestUpdateSeries(t *testing.T) { tests := []*starr.TestMockData{ { Name: "200", - ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=true"), + ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=false"), ExpectedMethod: "PUT", ExpectedRequest: updateSeries, ResponseStatus: 200, @@ -1165,7 +1165,7 @@ func TestUpdateSeries(t *testing.T) { }, { Name: "404", - ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=true"), + ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=false"), ExpectedMethod: "PUT", ExpectedRequest: updateSeries, ResponseStatus: 404, From 2177f20269c8789d07aa2eb4396f651b68e83031 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 30 Nov 2022 19:56:12 -0800 Subject: [PATCH 3/3] did wrong one on lidarr --- lidarr/album.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lidarr/album.go b/lidarr/album.go index 2928df9..c4fc40e 100644 --- a/lidarr/album.go +++ b/lidarr/album.go @@ -138,12 +138,12 @@ func (l *Lidarr) GetAlbumByIDContext(ctx context.Context, albumID int64) (*Album } // UpdateAlbum updates an album in place; the output of this is currently unknown!!!! -func (l *Lidarr) UpdateAlbum(albumID int64, album *Album) (*Album, error) { - return l.UpdateAlbumContext(context.Background(), albumID, album) +func (l *Lidarr) UpdateAlbum(albumID int64, album *Album, moveFiles bool) (*Album, error) { + return l.UpdateAlbumContext(context.Background(), albumID, album, moveFiles) } // UpdateAlbumContext updates an album in place; the output of this is currently unknown!!!! -func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *Album) (*Album, error) { +func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *Album, moveFiles bool) (*Album, error) { var body bytes.Buffer if err := json.NewEncoder(&body).Encode(album); err != nil { return nil, fmt.Errorf("json.Marshal(%s): %w", bpAlbum, err) @@ -156,6 +156,7 @@ func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *A Query: make(url.Values), Body: &body, } + req.Query.Add("moveFiles", fmt.Sprint(moveFiles)) if err := l.PutInto(ctx, req, &output); err != nil { return nil, fmt.Errorf("api.Put(%s): %w", &req, err) @@ -165,12 +166,12 @@ func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *A } // AddAlbum adds a new album to Lidarr, and probably does not yet work. -func (l *Lidarr) AddAlbum(album *AddAlbumInput, moveFiles bool) (*Album, error) { - return l.AddAlbumContext(context.Background(), album, moveFiles) +func (l *Lidarr) AddAlbum(album *AddAlbumInput) (*Album, error) { + return l.AddAlbumContext(context.Background(), album) } // AddAlbumContext adds a new album to Lidarr, and probably does not yet work. -func (l *Lidarr) AddAlbumContext(ctx context.Context, album *AddAlbumInput, moveFiles bool) (*Album, error) { +func (l *Lidarr) AddAlbumContext(ctx context.Context, album *AddAlbumInput) (*Album, error) { if album.Releases == nil { album.Releases = make([]*AddAlbumInputRelease, 0) } @@ -185,7 +186,6 @@ func (l *Lidarr) AddAlbumContext(ctx context.Context, album *AddAlbumInput, move Query: make(url.Values), Body: &body, } - req.Query.Add("moveFiles", fmt.Sprint(moveFiles)) var output Album if err := l.PostInto(ctx, req, &output); err != nil {