func TestNewFault(t *testing.T) {
	t.Parallel()
	tests := []struct {
		name         string
		giveInjector Injector
		giveOptions  []Option
		wantFault    *Fault
		wantErr      error
	}{
		{
			name:         "all options",
			giveInjector: newTestInjectorNoop(),
			giveOptions: []Option{
				WithEnabled(true),
				WithParticipation(1.0),
				WithPathBlocklist([]string{"/donotinject"}),
				WithPathAllowlist([]string{"/onlyinject"}),
				WithHeaderBlocklist(map[string]string{"block": "yes"}),
				WithHeaderAllowlist(map[string]string{"allow": "yes"}),
				WithRandSeed(100),
				WithRandFloat32Func(func() float32 { return 0.0 }),
			},
			wantFault: &Fault{
				enabled:       true,
				injector:      newTestInjectorNoop(),
				participation: 1.0,
				pathBlocklist: map[string]bool{
					"/donotinject": true,
				},
				pathAllowlist: map[string]bool{
					"/onlyinject": true,
				},
				headerBlocklist: map[string]string{
					"block": "yes",
				},
				headerAllowlist: map[string]string{
					"allow": "yes",
				},
				randSeed: 100,
				rand:     rand.New(rand.NewSource(100)),
				randF:    func() float32 { return 0.0 },
			},
			wantErr: nil,
		},
		{
			name:         "nil injector",
			giveInjector: nil,
			giveOptions:  nil,
			wantFault:    nil,
			wantErr:      ErrNilInjector,
		},
		{
			name:         "invalid percent",
			giveInjector: newTestInjectorNoop(),
			giveOptions: []Option{
				WithParticipation(100.0),
			},
			wantFault: nil,
			wantErr:   ErrInvalidPercent,
		},
		{
			name:         "option error",
			giveInjector: newTestInjectorNoop(),
			giveOptions: []Option{
				withError(),
			},
			wantFault: nil,
			wantErr:   errErrorOption,
		},
		{
			name:         "empty options",
			giveInjector: newTestInjectorNoop(),
			giveOptions:  []Option{},
			wantFault: &Fault{
				enabled:       false,
				injector:      newTestInjectorNoop(),
				participation: 0.0,
				pathBlocklist: nil,
				pathAllowlist: nil,
				randSeed:      defaultRandSeed,
				rand:          rand.New(rand.NewSource(defaultRandSeed)),
				randF:         rand.New(rand.NewSource(defaultRandSeed)).Float32,
			},
			wantErr: nil,
		},
	}
	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			f, err := NewFault(tt.giveInjector, tt.giveOptions...)
			if tt.wantFault != nil {
				f.randF = nil
				tt.wantFault.randF = nil
			}
			assert.Equal(t, tt.wantErr, err)
			assert.Equal(t, tt.wantFault, f)
		})
	}
}
TestNewFault tests NewFault.
package fault
import (
	"fmt"
	"math/rand"
	"net/http"
	"strings"
	"testing"
	"github.com/stretchr/testify/assert"
)