Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Android platform; Import testify; Fix tests #58

Merged
merged 2 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

### Misc

## [1.3.1] - 2021-06-21

- Add support for `Android` pages. [#53](https://github.com/mstruebing/tldr/pull/58) ([@conves](https://github.com/conves))

## [1.3.0] - 2020-10-05

- Add `history` function for the past page view. [#53](https://github.com/mstruebing/tldr/pull/53) ([@wudong](https://github.com/wudong))
Expand Down
47 changes: 14 additions & 33 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ import (
"strings"
"testing"
"time"
)

func contains(arr []string, str string) bool {
for _, a := range arr {
if a == str {
return true
}
}
return false
}
"github.com/stretchr/testify/require"
)

func TestCacheDir(t *testing.T) {
cacheDirectory, err := cacheDir()
Expand Down Expand Up @@ -58,35 +51,23 @@ func TestNewRepository(t *testing.T) {
}
}

func TestPlattforms(t *testing.T) {
func TestPlatforms(t *testing.T) {
remote := "https://tldr.sh/assets/tldr.zip"
ttl := time.Hour * 24 * 7
r, _ := NewRepository(remote, ttl)

platforms, _ := r.AvailablePlatforms()
if len(platforms) != 5 {
t.Error("Expected 5 Platforms, got", len(platforms))
}
r, err := NewRepository(remote, ttl)
require.NoError(t, err, "NewRepository() error %v", err)

if !contains(platforms, "linux") {
t.Error("Expected linux in platforms, got", platforms)
}

if !contains(platforms, "common") {
t.Error("Expected common in platforms, got", platforms)
}
platforms, err := r.AvailablePlatforms()
require.NoError(t, err, "AvailablePlatforms() error %v", err)

if !contains(platforms, "osx") {
t.Error("Expected osx in platforms, got", platforms)
}
require.Len(t, platforms, 6, "expected 5 platforms, got", len(platforms))

if !contains(platforms, "sunos") {
t.Error("Expected sunos in platforms, got", platforms)
}

if !contains(platforms, "windows") {
t.Error("Expected windows in platforms, got", platforms)
}
require.Contains(t, platforms, "android", "expected android in platforms, got", platforms)
require.Contains(t, platforms, "linux", "expected linux in platforms, got", platforms)
require.Contains(t, platforms, "common", "expected common in platforms, got", platforms)
require.Contains(t, platforms, "osx", "expected osx in platforms, got", platforms)
require.Contains(t, platforms, "sunos", "expected sunos in platforms, got", platforms)
require.Contains(t, platforms, "windows", "expected windows in platforms, got", platforms)
}

func TestReload(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/mstruebing/tldr

go 1.12

require github.com/stretchr/testify v1.7.0 // indirect
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/unidoc/unioffice v1.5.0 h1:RxPbPMBgKJ7gbqVlq/gZ+zd0gWWfvDUhm2ODbyMdfZk=
github.com/unidoc/unioffice v1.5.0/go.mod h1:7wl8btOkZW1TfqfpDWoujRXkUpowwisGRYDo7COHBiI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
67 changes: 32 additions & 35 deletions platform_test.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
package tldr

import (
"github.com/mstruebing/tldr/cache"
"testing"
"time"

"github.com/mstruebing/tldr/cache"
"github.com/stretchr/testify/require"
)

const (
remoteURL = "https://tldr.sh/assets/tldr.zip"
ttl = time.Hour * 24 * 7
)

func testSliceEqual(a, b []string) bool {

if a == nil && b == nil {
return true
}

if a == nil || b == nil {
return false
}

if len(a) != len(b) {
return false
}

for i := range a {
if a[i] != b[i] {
return false
}
}

return true
}

func TestCurrentPlattform(t *testing.T) {
var currentPlattform string = CurrentPlatform("linux")
currentPlattform := CurrentPlatform("linux")

if currentPlattform != "linux" {
t.Error("Expected linux, got ", currentPlattform)
Expand Down Expand Up @@ -78,16 +57,34 @@ func TestCurrentPlattform(t *testing.T) {
}

func TestAvailablePlatforms(t *testing.T) {
var availablePlatforms []string
repository, _ := cache.NewRepository(remoteURL, ttl)

availablePlatforms, _ = AvailablePlatforms(repository, "linux")
if !testSliceEqual([]string{"common", "linux", "osx", "sunos", "windows"}, availablePlatforms) {
t.Error("Expected to get all available platforms, got ", availablePlatforms)
tests := []struct {
name string
current string
want []string
wantErr bool
}{
{
name: "linux",
current: "linux",
want: []string{"android", "common", "linux", "osx", "sunos", "windows"},
},
{
name: "stuff",
current: "stuff",
want: []string{"android", "common", "linux", "osx", "sunos", "windows", "stuff"},
},
}

availablePlatforms, _ = AvailablePlatforms(repository, "stuff")
if !testSliceEqual([]string{"common", "linux", "osx", "sunos", "windows", "stuff"}, availablePlatforms) {
t.Error("Expected to get all available platforms including 'stuff', got ", availablePlatforms)
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

repository, err := cache.NewRepository(remoteURL, ttl)
require.NoError(t, err, "NewRepository() error %v", err)

got, err := AvailablePlatforms(repository, tt.current)
require.NoError(t, err, "AvailablePlatforms() error %v", err)
require.ElementsMatch(t, tt.want, got, "expected available platforms %s, got %s", tt.want, got)
})
}
}