golift.io/starr@v1.0.0/lidarr/indexerconfig_test.go (about) 1 package lidarr_test 2 3 import ( 4 "net/http" 5 "path" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "golift.io/starr" 10 "golift.io/starr/lidarr" 11 "golift.io/starr/starrtest" 12 ) 13 14 const indexerConfigBody = `{ 15 "minimumAge": 0, 16 "retention": 0, 17 "maximumSize": 0, 18 "rssSyncInterval": 20, 19 "id": 1 20 }` 21 22 func TestGetIndexerConfig(t *testing.T) { 23 t.Parallel() 24 25 tests := []*starrtest.MockData{ 26 { 27 Name: "200", 28 ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "config", "indexer"), 29 ExpectedMethod: "GET", 30 ResponseStatus: 200, 31 ResponseBody: indexerConfigBody, 32 WithResponse: &lidarr.IndexerConfig{ 33 ID: 1, 34 MaximumSize: 0, 35 MinimumAge: 0, 36 Retention: 0, 37 RssSyncInterval: 20, 38 }, 39 WithError: nil, 40 }, 41 { 42 Name: "404", 43 ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "config", "indexer"), 44 ExpectedMethod: "GET", 45 ResponseStatus: 404, 46 ResponseBody: `{"message": "NotFound"}`, 47 WithError: &starr.ReqError{Code: http.StatusNotFound}, 48 WithResponse: (*lidarr.IndexerConfig)(nil), 49 }, 50 } 51 52 for _, test := range tests { 53 test := test 54 t.Run(test.Name, func(t *testing.T) { 55 t.Parallel() 56 mockServer := test.GetMockServer(t) 57 client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0)) 58 output, err := client.GetIndexerConfig() 59 assert.ErrorIs(t, err, test.WithError, "error is not the same as expected") 60 assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected") 61 }) 62 } 63 } 64 65 func TestUpdateIndexerConfig(t *testing.T) { 66 t.Parallel() 67 68 tests := []*starrtest.MockData{ 69 { 70 Name: "202", 71 ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "config", "indexer", "1"), 72 ExpectedMethod: "PUT", 73 ResponseStatus: 202, 74 WithRequest: &lidarr.IndexerConfig{ 75 ID: 1, 76 MaximumSize: 0, 77 MinimumAge: 0, 78 Retention: 0, 79 RssSyncInterval: 20, 80 }, 81 ExpectedRequest: `{"id":1,"maximumSize":0,"minimumAge":0,"retention":0,"rssSyncInterval":20}` + "\n", 82 ResponseBody: indexerConfigBody, 83 WithResponse: &lidarr.IndexerConfig{ 84 ID: 1, 85 MaximumSize: 0, 86 MinimumAge: 0, 87 Retention: 0, 88 RssSyncInterval: 20, 89 }, 90 WithError: nil, 91 }, 92 { 93 Name: "404", 94 ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "config", "indexer", "1"), 95 ExpectedMethod: "PUT", 96 WithRequest: &lidarr.IndexerConfig{ 97 ID: 1, 98 MaximumSize: 0, 99 MinimumAge: 0, 100 Retention: 0, 101 RssSyncInterval: 20, 102 }, 103 ExpectedRequest: `{"id":1,"maximumSize":0,"minimumAge":0,"retention":0,"rssSyncInterval":20}` + "\n", 104 ResponseStatus: 404, 105 ResponseBody: `{"message": "NotFound"}`, 106 WithError: &starr.ReqError{Code: http.StatusNotFound}, 107 WithResponse: (*lidarr.IndexerConfig)(nil), 108 }, 109 } 110 111 for _, test := range tests { 112 test := test 113 t.Run(test.Name, func(t *testing.T) { 114 t.Parallel() 115 mockServer := test.GetMockServer(t) 116 client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0)) 117 output, err := client.UpdateIndexerConfig(test.WithRequest.(*lidarr.IndexerConfig)) 118 assert.ErrorIs(t, err, test.WithError, "error is not the same as expected") 119 assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected") 120 }) 121 } 122 }