diff --git a/content.go b/content.go index 3c81526..b055902 100644 --- a/content.go +++ b/content.go @@ -41,7 +41,7 @@ func domToNode(domNode *html.Node) interface{} { return nil } - var nodeElement NodeElement + nodeElement := new(NodeElement) switch strings.ToLower(domNode.Data) { case "a", "aside", "b", "blockquote", "br", "code", "em", "figcaption", "figure", "h3", "h4", "hr", "i", diff --git a/content_test.go b/content_test.go index 73cc211..abee664 100644 --- a/content_test.go +++ b/content_test.go @@ -1,25 +1,26 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestContentFormat(t *testing.T) { t.Run("invalid", func(t *testing.T) { - _, err := ContentFormat(42) - assert.EqualError(t, ErrInvalidDataType, err.Error()) + _, err := telegraph.ContentFormat(42) + assert.EqualError(t, telegraph.ErrInvalidDataType, err.Error()) }) t.Run("valid", func(t *testing.T) { t.Run("string", func(t *testing.T) { - validContentDOM, err := ContentFormat(`

Hello, World!

`) + validContentDOM, err := telegraph.ContentFormat(`

Hello, World!

`) assert.NoError(t, err) assert.NotEmpty(t, validContentDOM) }) t.Run("bytes", func(t *testing.T) { - validContentDOM, err := ContentFormat([]byte(`

Hello, World!

`)) + validContentDOM, err := telegraph.ContentFormat([]byte(`

Hello, World!

`)) assert.NoError(t, err) assert.NotEmpty(t, validContentDOM) }) diff --git a/create_account_test.go b/create_account_test.go index 105dfd6..5d74414 100644 --- a/create_account_test.go +++ b/create_account_test.go @@ -1,19 +1,20 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestCreateAccount(t *testing.T) { t.Run("invalid", func(t *testing.T) { t.Run("nil", func(t *testing.T) { - _, err := CreateAccount(Account{}) + _, err := telegraph.CreateAccount(telegraph.Account{}) assert.Error(t, err) }) t.Run("without shortname", func(t *testing.T) { - _, err := CreateAccount(Account{ + _, err := telegraph.CreateAccount(telegraph.Account{ ShortName: "", AuthorName: "Anonymous", }) @@ -21,7 +22,7 @@ func TestCreateAccount(t *testing.T) { }) }) t.Run("valid", func(t *testing.T) { - account, err := CreateAccount(Account{ + account, err := telegraph.CreateAccount(telegraph.Account{ ShortName: "Sandbox", AuthorName: "Anonymous", }) diff --git a/create_page_test.go b/create_page_test.go index 6c0f5e4..6a2943e 100644 --- a/create_page_test.go +++ b/create_page_test.go @@ -1,18 +1,19 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestCreatePage(t *testing.T) { - content, err := ContentFormat(`

Hello, world!

`) + content, err := telegraph.ContentFormat(`

Hello, world!

`) assert.NoError(t, err) t.Run("invalid", func(t *testing.T) { - var a Account - _, err := a.CreatePage(Page{ + var a telegraph.Account + _, err := a.CreatePage(telegraph.Page{ Title: "Sample Page", AuthorName: "Anonymous", Content: content, @@ -20,13 +21,13 @@ func TestCreatePage(t *testing.T) { assert.Error(t, err) }) t.Run("valid", func(t *testing.T) { - a := Account{ + a := telegraph.Account{ AccessToken: "b968da509bb76866c35425099bc0989a5ec3b32997d55286c657e6994bbb", ShortName: "Sandbox", AuthorName: "Anonymous", } - page, err := a.CreatePage(Page{ + page, err := a.CreatePage(telegraph.Page{ Title: "Sample Page", AuthorName: "Anonymous", Content: content, diff --git a/edit_account_info_test.go b/edit_account_info_test.go index 2c1d1c2..8c39415 100644 --- a/edit_account_info_test.go +++ b/edit_account_info_test.go @@ -1,25 +1,26 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestEditAccountInfo(t *testing.T) { t.Run("invalid", func(t *testing.T) { - var a Account - _, err := a.EditAccountInfo(Account{}) + var a telegraph.Account + _, err := a.EditAccountInfo(telegraph.Account{}) assert.Error(t, err) }) t.Run("valid", func(t *testing.T) { - a := Account{ + a := telegraph.Account{ AccessToken: "b968da509bb76866c35425099bc0989a5ec3b32997d55286c657e6994bbb", ShortName: "Sandbox", AuthorName: "Anonymous", } - _, err := a.EditAccountInfo(Account{ + _, err := a.EditAccountInfo(telegraph.Account{ ShortName: "Sandbox", AuthorName: "Anonymous", }) diff --git a/edit_page_test.go b/edit_page_test.go index acc8842..a30cc88 100644 --- a/edit_page_test.go +++ b/edit_page_test.go @@ -1,18 +1,19 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestEditPage(t *testing.T) { - content, err := ContentFormat("

Hello, world!

") + content, err := telegraph.ContentFormat("

Hello, world!

") assert.NoError(t, err) t.Run("invalid", func(t *testing.T) { - var a Account - _, err := a.EditPage(Page{ + var a telegraph.Account + _, err := a.EditPage(telegraph.Page{ Title: "Sample Page", AuthorName: "Anonymous", Content: content, @@ -20,13 +21,13 @@ func TestEditPage(t *testing.T) { assert.Error(t, err) }) t.Run("valid", func(t *testing.T) { - a := Account{ + a := telegraph.Account{ AccessToken: "b968da509bb76866c35425099bc0989a5ec3b32997d55286c657e6994bbb", ShortName: "Sandbox", AuthorName: "Anonymous", } - page, err := a.EditPage(Page{ + page, err := a.EditPage(telegraph.Page{ Path: "Sample-Page-12-15", Title: "Sample Page", AuthorName: "Anonymous", diff --git a/get_account_info_test.go b/get_account_info_test.go index 5dc2824..a56a1d9 100644 --- a/get_account_info_test.go +++ b/get_account_info_test.go @@ -1,25 +1,26 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestGetAccountInfo(t *testing.T) { t.Run("invalid", func(t *testing.T) { - var a Account + var a telegraph.Account _, err := a.GetAccountInfo() assert.Error(t, err) }) t.Run("valid", func(t *testing.T) { - a := Account{ + a := telegraph.Account{ AccessToken: "b968da509bb76866c35425099bc0989a5ec3b32997d55286c657e6994bbb", ShortName: "Sandbox", AuthorName: "Anonymous", } - info, err := a.GetAccountInfo(FieldShortName, FieldPageCount) + info, err := a.GetAccountInfo(telegraph.FieldShortName, telegraph.FieldPageCount) assert.NoError(t, err) assert.Equal(t, a.ShortName, info.ShortName) assert.NotZero(t, info.PageCount) diff --git a/get_page_list_test.go b/get_page_list_test.go index 000bb97..2017a5d 100644 --- a/get_page_list_test.go +++ b/get_page_list_test.go @@ -1,19 +1,20 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestGetPageList(t *testing.T) { t.Run("invalid", func(t *testing.T) { - var a Account + var a telegraph.Account _, err := a.GetPageList(0, 0) assert.Error(t, err) }) t.Run("valid", func(t *testing.T) { - a := Account{ + a := telegraph.Account{ AccessToken: "b968da509bb76866c35425099bc0989a5ec3b32997d55286c657e6994bbb", ShortName: "Sandbox", AuthorName: "Anonymous", diff --git a/get_page_test.go b/get_page_test.go index 32a0734..4157eef 100644 --- a/get_page_test.go +++ b/get_page_test.go @@ -1,18 +1,19 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestGetPage(t *testing.T) { t.Run("invalid", func(t *testing.T) { - _, err := GetPage("wtf", true) + _, err := telegraph.GetPage("wtf", true) assert.Error(t, err) }) t.Run("valid", func(t *testing.T) { - page, err := GetPage("Sample-Page-12-15", true) + page, err := telegraph.GetPage("Sample-Page-12-15", true) assert.NoError(t, err) assert.NotNil(t, page) }) diff --git a/get_views_test.go b/get_views_test.go index 65dec11..5d1574e 100644 --- a/get_views_test.go +++ b/get_views_test.go @@ -1,45 +1,46 @@ -package telegraph +package telegraph_test import ( "testing" "time" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestGetViews(t *testing.T) { t.Run("invalid", func(t *testing.T) { t.Run("path", func(t *testing.T) { - _, err := GetViews("wtf", time.Time{}) + _, err := telegraph.GetViews("wtf", time.Time{}) assert.Error(t, err) }) t.Run("year", func(t *testing.T) { dt := time.Date(1980, 0, 0, 0, 0, 0, 0, time.UTC) - _, err := GetViews("Sample-Page-12-15", dt) + _, err := telegraph.GetViews("Sample-Page-12-15", dt) assert.Error(t, err) }) t.Run("month", func(t *testing.T) { dt := time.Date(2000, 22, 0, 0, 0, 0, 0, time.UTC) - result, err := GetViews("Sample-Page-12-15", dt) + result, err := telegraph.GetViews("Sample-Page-12-15", dt) assert.NoError(t, err) assert.NotNil(t, result) }) t.Run("day", func(t *testing.T) { dt := time.Date(2000, time.February, 42, 0, 0, 0, 0, time.UTC) - result, err := GetViews("Sample-Page-12-15", dt) + result, err := telegraph.GetViews("Sample-Page-12-15", dt) assert.NoError(t, err) assert.NotNil(t, result) }) t.Run("hour", func(t *testing.T) { dt := time.Date(2000, time.February, 12, 65, 0, 0, 0, time.UTC) - result, err := GetViews("Sample-Page-12-15", dt) + result, err := telegraph.GetViews("Sample-Page-12-15", dt) assert.NoError(t, err) assert.NotNil(t, result) }) }) t.Run("valid", func(t *testing.T) { dt := time.Date(2016, time.December, 31, 0, 0, 0, 0, time.UTC) - stats, err := GetViews("Sample-Page-12-15", dt) + stats, err := telegraph.GetViews("Sample-Page-12-15", dt) assert.NoError(t, err) if !assert.NotNil(t, stats) { t.FailNow() diff --git a/revoke_access_token_test.go b/revoke_access_token_test.go index 69cadb4..ca9c54e 100644 --- a/revoke_access_token_test.go +++ b/revoke_access_token_test.go @@ -1,19 +1,20 @@ -package telegraph +package telegraph_test import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/toby3d/telegraph" ) func TestRevokeAccessToken(t *testing.T) { t.Run("invalid", func(t *testing.T) { - var account Account + var account telegraph.Account _, err := account.RevokeAccessToken() assert.Error(t, err) }) t.Run("valid", func(t *testing.T) { - a, err := CreateAccount(Account{ + a, err := telegraph.CreateAccount(telegraph.Account{ ShortName: "Sandbox", AuthorName: "Anonymous", }) diff --git a/telegraph.go b/telegraph.go index cf37de7..8fdb8c7 100644 --- a/telegraph.go +++ b/telegraph.go @@ -52,7 +52,7 @@ func makeRequest(path string, payload interface{}) ([]byte, error) { } if !r.Ok { - return nil, errors.New(r.Error) + return nil, errors.New(r.Error) //nolint: goerr113 } return r.Result, nil