-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from z3ntu/debian
Add support for debian.org
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package upstream | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"regexp" | ||
|
||
"github.com/go-errors/errors" | ||
) | ||
|
||
type debianVersion struct { | ||
Version string `json:"version"` | ||
} | ||
|
||
type debianResponse struct { | ||
Versions []debianVersion `json:"versions"` | ||
} | ||
|
||
type debian string | ||
|
||
func (d debian) releasesURL() string { | ||
// API documentation: https://sources.debian.org/doc/api/ | ||
return fmt.Sprintf("https://sources.debian.org/api/src/%s/", url.PathEscape(string(d))) | ||
} | ||
|
||
func (d debian) latestVersion() (Version, error) { | ||
var res debianResponse | ||
if err := fetchJSON(d, &res); err != nil { | ||
return "", errors.WrapPrefix(err, "No debian release found for "+string(d), 0) | ||
} | ||
match := regexp.MustCompile("([^-]+)[-|~]").FindStringSubmatch(res.Versions[0].Version) | ||
if len(match) > 0 { | ||
return Version(match[1]), nil | ||
} | ||
return Version(res.Versions[0].Version), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package upstream | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/h2non/gock" | ||
"github.com/simon04/aur-out-of-date/pkg" | ||
) | ||
|
||
func mockDebian() *gock.Response { | ||
return gock.New("https://sources.debian.org"). | ||
Get("/api/src/babeltrace/"). | ||
Reply(http.StatusOK). | ||
SetHeader("Content-Type", "application/json"). | ||
BodyString(` | ||
{ | ||
"package": "babeltrace", | ||
"path": "babeltrace", | ||
"pathl": [ | ||
[ | ||
"babeltrace", | ||
"/src/babeltrace/" | ||
] | ||
], | ||
"suite": "", | ||
"type": "package", | ||
"versions": [ | ||
{ | ||
"area": "main", | ||
"suites": [ | ||
"buster", | ||
"sid" | ||
], | ||
"version": "1.5.6-1" | ||
}, | ||
{ | ||
"area": "main", | ||
"suites": [ | ||
"stretch" | ||
], | ||
"version": "1.5.1-1" | ||
}, | ||
{ | ||
"area": "main", | ||
"suites": [ | ||
"jessie", | ||
"jessie-kfreebsd" | ||
], | ||
"version": "1.2.3-2" | ||
} | ||
] | ||
}`) | ||
} | ||
|
||
func TestDebianSource1(t *testing.T) { | ||
defer gock.Off() | ||
mockDebian() | ||
|
||
p := pkg.New("babeltrace", "0", "", "http://debian.backend.mirrors.debian.org/debian/pool/main/b/babeltrace/python3-babeltrace_1.5.6-1_hurd-i386.deb") | ||
version, err := VersionForPkg(p) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if version != "1.5.6" { | ||
t.Errorf("Expecting version 1.5.6, but got %v", version) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters