forked from zyedidia/eget
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94bc5a2
commit 91c663a
Showing
5 changed files
with
159 additions
and
40 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 |
---|---|---|
@@ -1,16 +1,21 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"errors" | ||
) | ||
|
||
type InvalidGitHubProjectURL = error | ||
type InvalidGitHubProjectReference = error | ||
|
||
var ( | ||
InvalidGitHubProjectURLError InvalidGitHubProjectURL = errors.New("Invalid GitHub project URL") | ||
InvalidGitHubProjectReferenceError InvalidGitHubProjectReference = errors.New("Invalid GitHub project reference") | ||
) | ||
|
||
func NewInvalidGitHubProjectURLError(URL string) InvalidGitHubProjectURL { | ||
return fmt.Errorf("Invalid GitHub URL: %s", URL) | ||
return InvalidGitHubProjectURLError | ||
} | ||
|
||
func NewInvalidGitHubProjectReferenceError(reference string) InvalidGitHubProjectReference { | ||
return fmt.Errorf("Invalid GitHub project reference: %s", reference) | ||
return InvalidGitHubProjectReferenceError | ||
} |
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,24 @@ | ||
package github_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/permafrost-dev/eget/lib/github" | ||
) | ||
|
||
var _ = Describe("GitHub Errors", func() { | ||
|
||
Describe("NewInvalidGitHubProjectURLError", func() { | ||
It("returns the InvalidGitHubProjectURLError", func() { | ||
err := github.NewInvalidGitHubProjectURLError("https://github.com/not/a/real/project") | ||
Expect(err).To(MatchError(github.InvalidGitHubProjectURLError)) | ||
}) | ||
}) | ||
|
||
Describe("NewInvalidGitHubProjectReferenceError", func() { | ||
It("returns the InvalidGitHubProjectReferenceError", func() { | ||
err := github.NewInvalidGitHubProjectReferenceError("master") | ||
Expect(err).To(MatchError(github.InvalidGitHubProjectReferenceError)) | ||
}) | ||
}) | ||
}) |
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
File renamed without changes.
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,90 @@ | ||
package github_test | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/permafrost-dev/eget/lib/assets" | ||
. "github.com/permafrost-dev/eget/lib/github" | ||
) | ||
|
||
var _ = Describe("Release", func() { | ||
var ( | ||
release Release | ||
) | ||
|
||
BeforeEach(func() { | ||
release = Release{ | ||
Assets: []ReleaseAsset{ | ||
{ | ||
Name: "asset1", | ||
URL: "http://example.com/asset1", | ||
DownloadURL: "http://example.com/download/asset1", | ||
Size: 1024, | ||
DownloadCount: 100, | ||
ContentType: "application/octet-stream", | ||
}, | ||
{ | ||
Name: "asset2", | ||
URL: "http://example.com/asset2", | ||
DownloadURL: "http://example.com/download/asset2", | ||
Size: 2048, | ||
DownloadCount: 200, | ||
ContentType: "application/octet-stream", | ||
}, | ||
}, | ||
Prerelease: false, | ||
Tag: "v1.0.0", | ||
CreatedAt: time.Now(), | ||
PublishedAt: time.Now(), | ||
} | ||
}) | ||
|
||
Describe("ProcessReleaseAssets", func() { | ||
It("should correctly associate each asset with its release", func() { | ||
release.ProcessReleaseAssets() | ||
for _, asset := range release.Assets { | ||
Expect(asset.Release).To(Equal(&release)) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
var _ = Describe("ReleaseAsset", func() { | ||
var ( | ||
releaseAsset ReleaseAsset | ||
release Release | ||
) | ||
|
||
BeforeEach(func() { | ||
release = Release{ | ||
Assets: nil, | ||
Prerelease: false, | ||
Tag: "v1.0.0", | ||
CreatedAt: time.Now(), | ||
PublishedAt: time.Now(), | ||
} | ||
|
||
releaseAsset = ReleaseAsset{ | ||
Release: &release, | ||
Name: "asset", | ||
URL: "http://example.com/asset", | ||
DownloadURL: "http://example.com/download/asset", | ||
Size: 1024, | ||
DownloadCount: 100, | ||
ContentType: "application/octet-stream", | ||
} | ||
}) | ||
|
||
Describe("CopyToNewAsset", func() { | ||
It("should correctly copy ReleaseAsset to Asset", func() { | ||
copiedAsset := releaseAsset.CopyToNewAsset() | ||
Expect(copiedAsset).To(Equal(assets.Asset{ | ||
Name: releaseAsset.Name, | ||
DownloadURL: releaseAsset.DownloadURL, | ||
ReleaseDate: releaseAsset.Release.PublishedAt, | ||
})) | ||
}) | ||
}) | ||
}) |