File: client_test.go

package info (click to toggle)
golang-github-andreykaipov-goobs 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,228 kB
  • sloc: makefile: 32
file content (71 lines) | stat: -rw-r--r-- 2,453 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package e2e

import (
	"fmt"
	"testing"

	"github.com/andreykaipov/goobs"
	"github.com/stretchr/testify/assert"
)

type customLogger struct{}

func (t customLogger) Printf(format string, v ...interface{}) {}

func Test_goobs_client_options(t *testing.T) {
	var client *goobs.Client
	var err error

	t.Run("basic", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "*goobs.discard")
	})

	t.Run("default logger used when only debug", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"), goobs.WithDebug(true))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "*log.Logger")
	})

	t.Run("custom logger implies debug logging", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"), goobs.WithLogger(customLogger{}))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "e2e.customLogger")
	})

	t.Run("custom logger but debug logging off", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"), goobs.WithLogger(customLogger{}), goobs.WithDebug(false))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "*goobs.discard")
	})
}

func Test_goobs_client_errors(t *testing.T) {
	var client *goobs.Client
	var err error

	t.Run("basic", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "*goobs.discard")
	})

	t.Run("default logger used when only debug", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"), goobs.WithDebug(true))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "*log.Logger")
	})

	t.Run("custom logger implies debug logging", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"), goobs.WithLogger(customLogger{}))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "e2e.customLogger")
	})

	t.Run("custom logger but debug logging off", func(t *testing.T) {
		client, err = goobs.New("localhost:4545", goobs.WithPassword("hello"), goobs.WithLogger(customLogger{}), goobs.WithDebug(false))
		assert.NoError(t, err)
		assert.Equal(t, fmt.Sprintf("%T", client.Log), "*goobs.discard")
	})
}