Skip to content

Commit

Permalink
Some improvements in the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
victorpopkov committed Dec 21, 2018
1 parent 4ba0344 commit 396228b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
38 changes: 34 additions & 4 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ func Example_gitHub() {

// example
a := appcast.New()
a.LoadFromRemoteSource("https://github.com/atom/atom/releases.atom")

p, errors := a.LoadFromRemoteSource("https://github.com/atom/atom/releases.atom")
if p != nil && len(errors) > 0 {
panic(errors[0])
}

fmt.Printf("%-9s %d error(s)\n", "Result:", len(errors))
fmt.Printf("%-9s %s\n", "Type:", reflect.TypeOf(a.Source().Appcast()))
fmt.Printf("%-9s %s\n", "Checksum:", a.Source().Checksum())
fmt.Printf("%-9s %s\n", "Provider:", a.Source().Provider())
Expand All @@ -63,6 +68,7 @@ func Example_gitHub() {
fmt.Printf("%12s %d total\n", "Downloads:", len(r.Downloads()))

// Output:
// Result: 0 error(s)
// Type: *github.Appcast
// Checksum: 03b6d9b8199ea377036caafa5358512295afa3c740edf9031dc6739b89e3ba05
// Provider: GitHub Atom Feed
Expand All @@ -88,9 +94,18 @@ func Example_sourceForge() {

// example
a := appcast.New()
a.LoadFromRemoteSource("https://sourceforge.net/projects/wesnoth/rss")

fmt.Printf("%-9s %s\n", "Type:", reflect.TypeOf(a.Source().Appcast()))
p, errors := a.LoadFromRemoteSource("https://sourceforge.net/projects/wesnoth/rss")
if p == nil && len(errors) > 0 {
panic(errors[0])
}

fmt.Print("Errors:\n\n")
for _, err := range errors {
fmt.Println(err)
}

fmt.Printf("%-10s %s\n", "\nType:", reflect.TypeOf(a.Source().Appcast()))
fmt.Printf("%-9s %s\n", "Checksum:", a.Source().Checksum())
fmt.Printf("%-9s %s\n", "Provider:", a.Source().Provider())
fmt.Printf("%-9s %d total\n\n", "Releases:", a.Releases().Len())
Expand Down Expand Up @@ -122,6 +137,14 @@ func Example_sourceForge() {
}

// Output:
// Errors:
//
// release #51 (no version)
// release #71 (no version)
// release #72 (no version)
// release #73 (no version)
// release #92 (no version)
//
// Type: *sourceforge.Appcast
// Checksum: 880cf7f2f6aa0aa0d859f1fc06e4fbcbba3d4de15fa9736bf73c07accb93ce36
// Provider: SourceForge RSS Feed
Expand Down Expand Up @@ -156,9 +179,15 @@ func Example_sparkle() {

// example
a := appcast.New()
a.LoadFromRemoteSource("https://www.adium.im/sparkle/appcast-release.xml")

p, errors := a.LoadFromRemoteSource("https://www.adium.im/sparkle/appcast-release.xml")
if p != nil && len(errors) > 0 {
panic(errors[0])
}

a.Releases().SortByVersions(release.DESC)

fmt.Printf("%-9s %d error(s)\n", "Result:", len(errors))
fmt.Printf("%-9s %s\n", "Type:", reflect.TypeOf(a.Source().Appcast()))
fmt.Printf("%-9s %s\n", "Checksum:", a.Source().Checksum())
fmt.Printf("%-9s %s\n", "Provider:", a.Source().Provider())
Expand All @@ -182,6 +211,7 @@ func Example_sparkle() {
fmt.Printf("%23s %s\n", "DSA Signature:", d.DsaSignature())

// Output:
// Result: 0 error(s)
// Type: *sparkle.Appcast
// Checksum: 6ec7c5abcaa78457cc4bf3c2196584446cca1461c65505cbaf0382a2f62128db
// Provider: Sparkle RSS Feed
Expand Down
4 changes: 2 additions & 2 deletions provider/github/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func Example() {
panic(err)
}

appcast, errors := a.Unmarshal()
if appcast != nil && len(errors) > 0 {
p, errors := a.Unmarshal()
if p == nil && len(errors) > 0 {
panic(errors[0])
}

Expand Down
5 changes: 4 additions & 1 deletion provider/sourceforge/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func Example() {
panic(err)
}

_, errors := a.Unmarshal()
p, errors := a.Unmarshal()
if p == nil && len(errors) > 0 {
panic(errors[0])
}

fmt.Print("Errors:\n\n")
for _, err := range errors {
Expand Down
4 changes: 2 additions & 2 deletions provider/sparkle/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func Example() {
panic(err)
}

appcast, errors := a.Unmarshal()
if appcast != nil && len(errors) > 0 {
p, errors := a.Unmarshal()
if p == nil && len(errors) > 0 {
panic(errors[0])
}

Expand Down

0 comments on commit 396228b

Please sign in to comment.