diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de4fe2..55edf38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/cache/cache_test.go b/cache/cache_test.go index bb936a3..2c629fe 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -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() @@ -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) { diff --git a/go.mod b/go.mod index af08023..b5745ee 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/mstruebing/tldr go 1.12 + +require github.com/stretchr/testify v1.7.0 // indirect diff --git a/go.sum b/go.sum index b08d8fb..a5c59c4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/platform_test.go b/platform_test.go index 91daea4..c6f5eb1 100644 --- a/platform_test.go +++ b/platform_test.go @@ -1,9 +1,11 @@ package tldr import ( - "github.com/mstruebing/tldr/cache" "testing" "time" + + "github.com/mstruebing/tldr/cache" + "github.com/stretchr/testify/require" ) const ( @@ -11,31 +13,8 @@ const ( 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) @@ -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) + }) } }