Browse Source

Add test for Publisher

resolves #20
pull/21/head
Efertone 11 months ago
parent
commit
698e05b6d8
Signed by: efertone GPG Key ID: 58E2D23885002DC5
4 changed files with 62 additions and 1 deletions
  1. +6
    -0
      pkg/misskey/client.go
  2. +1
    -1
      pkg/publisher/misskey.go
  3. +29
    -0
      pkg/publisher/misskey_test.go
  4. +26
    -0
      pkg/publisher/publisher_test.go

+ 6
- 0
pkg/misskey/client.go View File

@ -14,6 +14,12 @@ type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
// ClientInterface is an interface to describe how a Client looks like.
// Mostly for Mocking. Or later if Misskey gets multiple API versions.
type ClientInterface interface {
CreateNote(content string) error
}
// Client is the main Misskey client struct.
type Client struct {
BaseURL string


+ 1
- 1
pkg/publisher/misskey.go View File

@ -4,7 +4,7 @@ import "gitea.code-infection.com/efertone/kiki/pkg/misskey"
// Misskey publisher.
type Misskey struct {
Client *misskey.Client
Client misskey.ClientInterface
}
const (


+ 29
- 0
pkg/publisher/misskey_test.go View File

@ -0,0 +1,29 @@
package publisher_test
import (
"testing"
"gitea.code-infection.com/efertone/kiki/pkg/publisher"
)
type MockMisskeyClient struct {
}
func (m MockMisskeyClient) CreateNote(content string) error {
return nil
}
func TestMisskeyPublisher(t *testing.T) {
pub := publisher.NewMisskey("https://localhost", "token")
pub.Client = &MockMisskeyClient{}
if pub.Name() != "misskey" {
t.Errorf("publisher.Name(): expected = misskey; got = %s", pub.Name())
}
err := pub.Publish("test")
if err != nil {
t.Errorf("Unexpedted error: %s", err)
}
}

+ 26
- 0
pkg/publisher/publisher_test.go View File

@ -0,0 +1,26 @@
package publisher_test
import (
"testing"
"gitea.code-infection.com/efertone/kiki/pkg/publisher"
)
func TestNewTokenPublisherByName_Misskey(t *testing.T) {
pub := publisher.NewTokenPublisherByName("misskey", "url", "token")
if pub == nil {
t.Error("Expected Misskey Publisher, got nothing")
return
}
if pub.Name() != "misskey" {
t.Errorf("Expected Name() = misskey, got %s", pub.Name())
}
}
func TestNewTokenPublisherByName_Unknown(t *testing.T) {
pub := publisher.NewTokenPublisherByName("unknown", "url", "token")
if pub != nil {
t.Errorf("Unexpected Publisher: %s", pub.Name())
}
}

Loading…
Cancel
Save