Skip to content

Commit

Permalink
Add corner cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
googollee committed Apr 9, 2024
1 parent 1e664d2 commit 58008dd
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions module/cornercases_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package module

import (
"context"
"testing"
)

func TestProviderReturnNilInterfaceWithoutError(t *testing.T) {
type Interface interface{}
newNilInterface := func(context.Context) (Interface, error) {
return nil, nil
}
moduleInterface := New(newNilInterface)

repo := NewRepo()
repo.AddModule(moduleInterface)

ctx, err := repo.InjectTo(context.Background())
if err != nil {
t.Fatal("inject error:", err)
}

var got Interface = moduleInterface.Value(ctx)
if got != nil {
t.Errorf("moduleInterface.Value(ctx) = %v, want: nil", got)
}
}

func TestProviderReturnNilPointerWithoutError(t *testing.T) {
type Instance struct{}
newNilInstance := func(context.Context) (*Instance, error) {
return nil, nil
}
moduleInstance := New(newNilInstance)

repo := NewRepo()
repo.AddModule(moduleInstance)

ctx, err := repo.InjectTo(context.Background())
if err != nil {
t.Fatal("inject error:", err)
}

var got *Instance = moduleInstance.Value(ctx)
if got != nil {
t.Errorf("moduleInstance.Value(ctx) = %v, want: nil", got)
}
}

0 comments on commit 58008dd

Please sign in to comment.