File: log_test.go

package info (click to toggle)
golang-github-smallstep-certificates 0.20.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,144 kB
  • sloc: sh: 278; makefile: 170
file content (44 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (2)
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
package log

import (
	"errors"
	"net/http"
	"net/http/httptest"
	"reflect"
	"testing"

	"github.com/smallstep/certificates/logging"
)

func TestError(t *testing.T) {
	theError := errors.New("the error")

	type args struct {
		rw  http.ResponseWriter
		err error
	}
	tests := []struct {
		name       string
		args       args
		withFields bool
	}{
		{"normalLogger", args{httptest.NewRecorder(), theError}, false},
		{"responseLogger", args{logging.NewResponseLogger(httptest.NewRecorder()), theError}, true},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			Error(tt.args.rw, tt.args.err)
			if tt.withFields {
				if rl, ok := tt.args.rw.(logging.ResponseLogger); ok {
					fields := rl.Fields()
					if !reflect.DeepEqual(fields["error"], theError) {
						t.Errorf("ResponseLogger[\"error\"] = %s, wants %s", fields["error"], theError)
					}
				} else {
					t.Error("ResponseWriter does not implement logging.ResponseLogger")
				}
			}
		})
	}
}