Add tests
This commit is contained in:
43
pkg/config/ctx_test.go
Normal file
43
pkg/config/ctx_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFromCtx(t *testing.T) {
|
||||
app := &AppConfig{
|
||||
Name: "testapp",
|
||||
}
|
||||
appCtx := app.AddToCtx(context.Background())
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Unprepared app context",
|
||||
args: args{ctx: context.Background()},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Prepared app context",
|
||||
args: args{ctx: appCtx},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := FromCtx(tt.args.ctx)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FromCtx() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user