Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kynrai committed Jun 11, 2024
1 parent 46fd931 commit c2d495a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions checks/social_tags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package checks

import (
"context"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/xray-web/web-check-api/testutils"
)

func TestSocialTagsEmpty(t *testing.T) {
t.Parallel()

t.Run("Empty", func(t *testing.T) {
t.Parallel()

s := SocialTagsData{}
assert.True(t, s.Empty())
})

t.Run("Not empty", func(t *testing.T) {
t.Parallel()

s := SocialTagsData{
Title: "Example Domain",
}
assert.False(t, s.Empty())
})
}

func TestNewSocialTags(t *testing.T) {
t.Parallel()

t.Run("No social tags", func(t *testing.T) {
t.Parallel()

client := testutils.MockClient(testutils.Response(http.StatusOK, []byte{}))
tags, err := NewSocialTags(client).GetSocialTags(context.TODO(), "http://example.com")
assert.NoError(t, err)
assert.True(t, tags.Empty())
})

t.Run("Social tags", func(t *testing.T) {
t.Parallel()

var html = []byte(`
<html>
<head>
<title>Example Domain</title>
<meta name="description" content="Example description">
<meta property="og:title" content="Example OG Title">
</head>
<body></body>
</html>
`)
client := testutils.MockClient(testutils.Response(http.StatusOK, html))
tags, err := NewSocialTags(client).GetSocialTags(context.TODO(), "http://example.com")
assert.NoError(t, err)
assert.False(t, tags.Empty())
assert.Equal(t, "Example description", tags.Description)
assert.Equal(t, "Example Domain", tags.Title)
assert.Equal(t, "Example OG Title", tags.OgTitle)
})
}

0 comments on commit c2d495a

Please sign in to comment.