github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/tequilapi/launchpad/api_test.go (about) 1 /* 2 * Copyright (C) 2022 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package launchpad 19 20 import ( 21 "bytes" 22 "io" 23 "net/http" 24 "testing" 25 26 "github.com/stretchr/testify/assert" 27 ) 28 29 type mockLaunchpadAPI struct { 30 } 31 32 func (m *mockLaunchpadAPI) Do(req *http.Request) (*http.Response, error) { 33 return &http.Response{ 34 Status: "200 OK", 35 StatusCode: http.StatusOK, 36 Body: io.NopCloser(bytes.NewBufferString(responseJSON)), 37 }, nil 38 } 39 40 func TestLocalAPIServerPortIsAsExpected(t *testing.T) { 41 // given 42 mockAPI := mockLaunchpadAPI{} 43 c := cache{} 44 api := API{ 45 cache: &c, 46 http: &mockAPI, 47 } 48 49 // expect 50 assert.True(t, c.expiresAt.IsZero()) 51 assert.Equal(t, 0, len(c.response.Entries)) 52 53 // when 54 version, err := api.LatestPublishedReleaseVersion() 55 assert.NoError(t, err) 56 assert.Equal(t, "1.17.4", version) 57 58 // expect 59 assert.True(t, !c.expiresAt.IsZero()) 60 assert.Equal(t, 1, len(c.response.Entries)) 61 assert.Equal(t, "1.17.4+build648396996+jammy", c.response.Entries[0].BinaryPackageVersion) 62 } 63 64 type mockHTTPClient struct { 65 } 66 67 const responseJSON = `{ 68 "start": 0, 69 "total_size": 1, 70 "entries": [ 71 { 72 "self_link": "https://api.launchpad.net/1.0/~mysteriumnetwork/+archive/ubuntu/node/+binarypub/181640873", 73 "resource_type_link": "https://api.launchpad.net/1.0/#binary_package_publishing_history", 74 "display_name": "myst 1.17.4+build648396996+jammy in jammy amd64", 75 "component_name": "main", 76 "section_name": "devel", 77 "source_package_name": "myst", 78 "source_package_version": "1.17.4+build648396996+jammy", 79 "distro_arch_series_link": "https://api.launchpad.net/1.0/ubuntu/jammy/amd64", 80 "phased_update_percentage": null, 81 "date_published": "2022-09-26T07:33:30.656503+00:00", 82 "scheduled_deletion_date": null, 83 "status": "Published", 84 "pocket": "Release", 85 "creator_link": null, 86 "date_created": "2022-09-26T07:16:19.827227+00:00", 87 "date_superseded": null, 88 "date_made_pending": null, 89 "date_removed": null, 90 "archive_link": "https://api.launchpad.net/1.0/~mysteriumnetwork/+archive/ubuntu/node", 91 "copied_from_archive_link": "https://api.launchpad.net/1.0/~mysteriumnetwork/+archive/ubuntu/node-pre", 92 "removed_by_link": null, 93 "removal_comment": null, 94 "binary_package_name": "myst", 95 "binary_package_version": "1.17.4+build648396996+jammy", 96 "build_link": "https://api.launchpad.net/1.0/~mysteriumnetwork/+archive/ubuntu/node-pre/+build/24496120", 97 "architecture_specific": true, 98 "priority_name": "OPTIONAL", 99 "http_etag": "\"b96c547d46dd408be77abacfebd555f2e927927b-c4489c5b704cdb2055d97c780aeaf46f74b72c73\"" 100 } 101 ] 102 }`