Skip to content

Commit

Permalink
Add new tests
Browse files Browse the repository at this point in the history
Exclude example directory from tests
  • Loading branch information
stillya committed Aug 27, 2023
1 parent b5337fb commit c1d9901
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func main() {
goidc.Opts{
BaseURL: "http://localhost:8085",
UseAsymmetricEnc: true,
PublicKey: "example/testdata/public.jwks",
PrivateKey: "example/testdata/private.jwks",
PublicKey: "_example/testdata/public.jwks",
PrivateKey: "_example/testdata/private.jwks",
Issuer: "goidc",
Audience: "goidc",
AccessTokenLifetime: time.Minute * 15,
Expand Down
4 changes: 2 additions & 2 deletions example/main.go → _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func main() {
goidc.Opts{
BaseURL: "http://localhost:8085",
UseAsymmetricEnc: true,
PublicKey: "example/testdata/public.jwks",
PrivateKey: "example/testdata/private.jwks",
PublicKey: "_example/testdata/public.jwks",
PrivateKey: "_example/testdata/private.jwks",
Issuer: "goidc",
Audience: "goidc",
AccessTokenLifetime: time.Minute * 15,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions logger/logger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package logger

import (
"bytes"
"fmt"
"log"
"os"
"strings"
"testing"
)

func TestLogger(t *testing.T) {
buff := bytes.NewBufferString("")
lg := Func(func(format string, args ...interface{}) {
fmt.Fprintf(buff, format, args...)
})

lg.Logf("blah %s %d something", "str", 123)

if !strings.HasSuffix(buff.String(), "blah str 123 something") {
t.Errorf("wrong log output: %s", buff.String())
}
}

func TestStd(t *testing.T) {
buff := bytes.NewBufferString("")
log.SetOutput(buff)
defer log.SetOutput(os.Stdout)

Std.Logf("blah %s %d something", "str", 123)

if !strings.HasSuffix(buff.String(), "blah str 123 something\n") {
t.Errorf("wrong log output: %s", buff.String())
}
}

func TestNoOp(t *testing.T) {
buff := bytes.NewBufferString("")
log.SetOutput(buff)
defer log.SetOutput(os.Stdout)

NoOp.Logf("blah %s %d something", "str", 123)

if buff.String() != "" {
t.Errorf("wrong log output: %s", buff.String())
}
}
42 changes: 42 additions & 0 deletions user/user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package user

import "testing"

func TestUser_SetAttr(t *testing.T) {
type fields struct {
UserID string
Username string
Attributes map[string]interface{}
Disabled bool
}
tests := []struct {
name string
fields fields
}{
{
name: "TestUser_SetAttr",
fields: fields{
UserID: "test",
Username: "test",
Attributes: make(map[string]interface{}),
Disabled: false,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
u := &User{
UserID: tt.fields.UserID,
Username: tt.fields.Username,
Attributes: tt.fields.Attributes,
Disabled: tt.fields.Disabled,
}
u.SetAttr("test", "test")

if u.Attributes["test"] != "test" {
t.Errorf("SetAttr() error = %v", u.Attributes["test"])
return
}
})
}
}

0 comments on commit c1d9901

Please sign in to comment.