• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang config.WithMockValues函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/corestoreio/csfw/config.WithMockValues函数的典型用法代码示例。如果您正苦于以下问题:Golang WithMockValues函数的具体用法?Golang WithMockValues怎么用?Golang WithMockValues使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了WithMockValues函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestIntCSV

func TestIntCSV(t *testing.T) {
	t.Parallel()
	defer debugLogBuf.Reset()
	defer infoLogBuf.Reset()

	b := model.NewIntCSV(
		"web/cors/int_slice",
		model.WithConfigStructure(configStructure),
		model.WithSourceByInt(source.Ints{
			{2014, "Year 2014"},
			{2015, "Year 2015"},
			{2016, "Year 2016"},
			{2017, "Year 2017"},
		}),
	)

	assert.Len(t, b.Options(), 4)

	assert.Exactly(t, []int{2014, 2015, 2016}, b.Get(config.NewMockGetter().NewScoped(0, 0, 4)))
	assert.Exactly(t, "web/cors/int_slice", b.String())

	wantPath := scope.StrStores.FQPathInt64(4, "web/cors/int_slice")
	assert.Exactly(t, []int{}, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "3015,3016",
		}),
	).NewScoped(0, 0, 4)))

	assert.Contains(t, debugLogBuf.String(), "The value '3015' cannot be found within the allowed Options")
	assert.Contains(t, debugLogBuf.String(), "The value '3016' cannot be found within the allowed Options")

	assert.Exactly(t, []int{2015, 2017}, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "2015,2017",
		}),
	).NewScoped(0, 0, 4)))

	mw := &config.MockWrite{}
	b.Source.Merge(source.NewByInt(source.Ints{
		{2018, "Year 2018"},
	}))
	assert.NoError(t, b.Write(mw, []int{2016, 2017, 2018}, scope.StoreID, 4))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "2016,2017,2018", mw.ArgValue.(string))

	//t.Log("\n", debugLogBuf.String())

}
开发者ID:joao-parana,项目名称:csfw,代码行数:48,代码来源:slices_test.go


示例2: TestWithValidateBaseUrl_ActivatedAndShouldNotRedirectWithPOSTRequest

func TestWithValidateBaseUrl_ActivatedAndShouldNotRedirectWithPOSTRequest(t *testing.T) {

	mockReader := config.NewMockReader(
		config.WithMockValues(config.MockPV{
			config.MockPathScopeDefault(store.PathRedirectToBase): 301,
		}),
	)

	w := httptest.NewRecorder()
	req, err := http.NewRequest(httputils.MethodGet, "http://corestore.io/catalog/product/view", nil)
	assert.NoError(t, err)

	mw := store.WithValidateBaseURL(mockReader)(finalHandlerWithValidateBaseURL(t))

	err = mw.ServeHTTPContext(context.Background(), w, req)
	assert.EqualError(t, err, store.ErrContextServiceNotFound.Error())

	w = httptest.NewRecorder()
	req, err = http.NewRequest(httputils.MethodPost, "http://corestore.io/catalog/product/view", strings.NewReader(`{ "k1": "v1",  "k2": { "k3": ["va1"]  }}`))
	assert.NoError(t, err)

	err = mw.ServeHTTPContext(context.Background(), w, req)
	assert.NoError(t, err)

}
开发者ID:levcom,项目名称:csfw,代码行数:25,代码来源:middleware_test.go


示例3: TestConfigRedirectToBase

func TestConfigRedirectToBase(t *testing.T) {
	defer debugLogBuf.Reset()
	t.Parallel()

	r := backend.NewConfigRedirectToBase(
		backend.Backend.WebURLRedirectToBase.String(),
		model.WithConfigStructure(backend.ConfigStructure),
	)

	cr := config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			backend.Backend.WebURLRedirectToBase.FQPathInt64(scope.StrDefault, 0): 2,
		}),
	)

	code := r.Get(cr.NewScoped(0, 0, 0))
	assert.Exactly(t, 2, code)
	code = r.Get(cr.NewScoped(1, 1, 2))
	assert.Exactly(t, 0, code)

	// that is crap we should return an error
	assert.Contains(t, debugLogBuf.String(), "Scope permission insufficient: Have 'Store'; Want 'Default'")

	mw := new(config.MockWrite)
	assert.EqualError(t, r.Write(mw, 200, scope.DefaultID, 0),
		"Cannot find 200 in list: [{\"Value\":0,\"Label\":\"No\"},{\"Value\":1,\"Label\":\"Yes (302 Found)\"},{\"Value\":302,\"Label\":\"Yes (302 Found)\"},{\"Value\":301,\"Label\":\"Yes (301 Moved Permanently)\"}]\n",
	) // 200 not allowed

}
开发者ID:joao-parana,项目名称:csfw,代码行数:29,代码来源:config_models_test.go


示例4: TestStringCSV

func TestStringCSV(t *testing.T) {
	t.Parallel()
	wantPath := scope.StrDefault.FQPathInt64(0, "web/cors/exposed_headers")
	b := model.NewStringCSV(
		"web/cors/exposed_headers",
		model.WithConfigStructure(configStructure),
		model.WithSourceByString(
			"Content-Type", "Content Type", "X-CoreStore-ID", "CoreStore Microservice ID",
		),
	)

	assert.NotEmpty(t, b.Options())

	assert.Exactly(t, []string{"Content-Type", "X-CoreStore-ID"}, b.Get(config.NewMockGetter().NewScoped(0, 0, 0)))

	assert.Exactly(t, []string{"Content-Application", "X-Gopher"}, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "Content-Application,X-Gopher",
		}),
	).NewScoped(0, 0, 0)))

	mw := &config.MockWrite{}
	b.Source.Merge(source.NewByString("a", "a", "b", "b", "c", "c"))

	assert.NoError(t, b.Write(mw, []string{"a", "b", "c"}, scope.DefaultID, 0))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "a,b,c", mw.ArgValue.(string))
}
开发者ID:joao-parana,项目名称:csfw,代码行数:28,代码来源:slices_test.go


示例5: TestScopedService

func TestScopedService(t *testing.T) {
	tests := []struct {
		desc                        string
		fqpath                      string
		path                        []string
		websiteID, groupID, storeID int64
		err                         error
	}{
		{
			"Default ScopedGetter should return default scope",
			scope.StrDefault.FQPath("0", "a/b/c"), []string{"a/b/c"}, 0, 0, 0, nil,
		},
		{
			"Website ID 1 ScopedGetter should fall back to default scope",
			scope.StrDefault.FQPath("0", "a/b/c"), []string{"a/b/c"}, 1, 0, 0, nil,
		},
		{
			"Website ID 10 + Group ID 12 ScopedGetter should fall back to website 10 scope",
			scope.StrWebsites.FQPath("10", "a/b/c"), []string{"a/b/c"}, 10, 12, 0, nil,
		},
		{
			"Website ID 10 + Group ID 12 + Store 22 ScopedGetter should fall back to website 10 scope",
			scope.StrWebsites.FQPath("10", "a/b/c"), []string{"a/b/c"}, 10, 12, 22, nil,
		},
		{
			"Website ID 10 + Group ID 12 + Store 22 ScopedGetter should return Store 22 scope",
			scope.StrStores.FQPath("22", "a/b/c"), []string{"a/b/c"}, 10, 12, 22, nil,
		},
		{
			"Website ID 10 + Group ID 12 + Store 42 ScopedGetter should return nothing",
			scope.StrStores.FQPath("22", "a/b/c"), []string{"a/b/c"}, 10, 12, 42, config.ErrKeyNotFound,
		},
		{
			"Path consists of only two elements which is incorrect",
			scope.StrDefault.FQPath("0", "a/b/c"), []string{"a", "b"}, 0, 0, 0, config.ErrPathEmpty,
		},
	}

	vals := []interface{}{"Gopher", true, float64(3.14159), int(2016), time.Now()}

	for vi, val := range vals {
		for _, test := range tests {

			cg := config.NewMockGetter(config.WithMockValues(config.MockPV{
				test.fqpath: val,
			}))

			sg := cg.NewScoped(test.websiteID, test.groupID, test.storeID)

			switch val.(type) {
			case string:
				s, err := sg.String(test.path...)
				testScopedService(t, s, test.desc, err, test.err)
			default:
				t.Fatalf("Unsupported type: %#v in index %d", val, vi)
			}
		}
	}
}
开发者ID:joao-parana,项目名称:csfw,代码行数:59,代码来源:service_scoped_test.go


示例6: TestAllowedCountriesDefault

func TestAllowedCountriesDefault(t *testing.T) {
	cr := config.NewMockReader(
		config.WithMockValues(config.MockPV{}),
	)

	haveCountries, err := directory.AllowedCountries(cr.NewScoped(1, 1, 1))
	assert.NoError(t, err)
	assert.True(t, len(haveCountries) > 100)
}
开发者ID:levcom,项目名称:csfw,代码行数:9,代码来源:country_test.go


示例7: TestAllowedCountriesFound

func TestAllowedCountriesFound(t *testing.T) {
	cr := config.NewMockReader(
		config.WithMockValues(config.MockPV{
			config.MockPathScopeStore(1, directory.PathCountryAllowed): "DE,AU,CH,AT",
		}),
	)

	haveCountries, err := directory.AllowedCountries(cr.NewScoped(1, 1, 1))
	assert.NoError(t, err)
	assert.Exactly(t, utils.StringSlice{"DE", "AU", "CH", "AT"}, haveCountries)
}
开发者ID:levcom,项目名称:csfw,代码行数:11,代码来源:country_test.go


示例8: TestPathGeneralCountryAllowDefault

func TestPathGeneralCountryAllowDefault(t *testing.T) {
	t.Parallel()
	defer debugLogBuf.Reset()

	cr := config.NewMockGetter(
		config.WithMockValues(config.MockPV{}),
	)

	haveCountries := directory.Backend.GeneralCountryAllow.Get(cr.NewScoped(1, 1, 1))

	assert.Exactly(t,
		[]string{"AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AX", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BL", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "VG", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CD", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CK", "CR", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GG", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GN", "GW", "GY", "HT", "HM", "HN", "HK", "HU", "IS", "IM", "IN", "ID", "IR", "IQ", "IE", "IL", "IT", "CI", "JE", "JM", "JP", "JO", "KZ", "KE", "KI", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "ME", "MF", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "FX", "MX", "FM", "MD", "MC", "MN", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "KP", "MP", "NO", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PS", "PT", "PR", "QA", "RE", "RO", "RS", "RU", "RW", "SH", "KN", "LC", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS", "KR", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TL", "TW", "TJ", "TZ", "TH", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "VI", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VA", "VE", "VN", "WF", "EH", "YE", "ZM", "ZW"},
		haveCountries,
	)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:15,代码来源:country_test.go


示例9: TestWithValidateBaseUrl_DeactivatedAndShouldNotRedirectWithGETRequest

func TestWithValidateBaseUrl_DeactivatedAndShouldNotRedirectWithGETRequest(t *testing.T) {

	mockReader := config.NewMockReader(
		config.WithMockValues(config.MockPV{
			config.MockPathScopeDefault(store.PathRedirectToBase): 0,
		}),
	)

	// no post request but check deactivated
	w := httptest.NewRecorder()
	req, err := http.NewRequest(httputils.MethodGet, "http://corestore.io/catalog/product/view", nil)
	assert.NoError(t, err)

	err = store.WithValidateBaseURL(mockReader)(finalHandlerWithValidateBaseURL(t)).ServeHTTPContext(context.Background(), w, req)
	assert.NoError(t, err)
}
开发者ID:levcom,项目名称:csfw,代码行数:16,代码来源:middleware_test.go


示例10: TestPasswordFromConfig

func TestPasswordFromConfig(t *testing.T) {

	cfg := config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			scope.StrDefault.FQPathInt64(ctxjwt.PathJWTPassword): `Rump3lst!lzch3n`,
		}),
	)

	jm, err := ctxjwt.NewService(
		ctxjwt.WithPasswordFromConfig(cfg),
	)
	assert.NoError(t, err)

	theToken, _, err := jm.GenerateToken(nil)
	assert.NoError(t, err)
	assert.NotEmpty(t, theToken)

}
开发者ID:joao-parana,项目名称:csfw,代码行数:18,代码来源:options_test.go


示例11: TestNewConfigCurrencyGet

func TestNewConfigCurrencyGet(t *testing.T) {
	t.Parallel()
	cc := directory.NewConfigCurrency(directory.Backend.CurrencyOptionsBase.String())

	cr := config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			directory.Backend.CurrencyOptionsBase.FQPathInt64(scope.StrStores, 1): "EUR",
			directory.Backend.CurrencyOptionsBase.FQPathInt64(scope.StrStores, 2): "WIR", // Special Swiss currency
		}),
	)

	cur, err := cc.Get(cr.NewScoped(1, 1, 1))
	assert.NoError(t, err)
	assert.Exactly(t, directory.MustNewCurrencyISO("EUR"), cur)

	cur, err = cc.Get(cr.NewScoped(1, 1, 2))
	assert.EqualError(t, err, "currency: tag is not a recognized currency")
	assert.Exactly(t, directory.Currency{}, cur)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:19,代码来源:config_models_test.go


示例12: TestPathCountryAllowedCustom

func TestPathCountryAllowedCustom(t *testing.T) {
	t.Parallel()
	defer debugLogBuf.Reset()

	previous := directory.Backend.GeneralCountryAllow.Option(model.WithSourceByString(
		"DE", "Germany", "AU", "'Straya", "CH", "Switzerland",
	))
	defer directory.Backend.GeneralCountryAllow.Option(previous)

	cr := config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			directory.Backend.GeneralCountryAllow.FQPathInt64(scope.StrStores, 1): "DE,AU,CH,AT",
		}),
	)

	haveCountries := directory.Backend.GeneralCountryAllow.Get(cr.NewScoped(1, 1, 1))

	assert.Exactly(t, []string{"DE", "AU", "CH", "AT"}, haveCountries)
	// todo validation
}
开发者ID:joao-parana,项目名称:csfw,代码行数:20,代码来源:country_test.go


示例13: TestFloat64

func TestFloat64(t *testing.T) {
	t.Parallel()
	wantPath := scope.StrWebsites.FQPathInt64(10, "web/cors/float64")
	b := model.NewFloat64("web/cors/float64", model.WithConfigStructure(configStructure))

	assert.Empty(t, b.Options())

	assert.Exactly(t, 2015.1000001, b.Get(config.NewMockGetter().NewScoped(0, 0, 0)))

	assert.Exactly(t, 2016.1000001, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: 2016.1000001,
		}),
	).NewScoped(10, 0, 0)))

	mw := &config.MockWrite{}
	assert.NoError(t, b.Write(mw, 1.123456789, scope.WebsiteID, 10))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "1.12345678900000", mw.ArgValue.(string))
}
开发者ID:joao-parana,项目名称:csfw,代码行数:20,代码来源:primitives_test.go


示例14: TestStr

func TestStr(t *testing.T) {
	t.Parallel()
	wantPath := scope.StrDefault.FQPathInt64(0, "web/cors/exposed_headers")
	b := model.NewStr("web/cors/exposed_headers", model.WithConfigStructure(configStructure))

	assert.Empty(t, b.Options())

	assert.Exactly(t, "Content-Type,X-CoreStore-ID", b.Get(config.NewMockGetter().NewScoped(0, 0, 0)))

	assert.Exactly(t, "X-Gopher", b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "X-Gopher",
		}),
	).NewScoped(0, 0, 0)))

	mw := &config.MockWrite{}
	assert.NoError(t, b.Write(mw, "dude", scope.DefaultID, 0))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "dude", mw.ArgValue.(string))
}
开发者ID:joao-parana,项目名称:csfw,代码行数:20,代码来源:primitives_test.go


示例15: TestBool

func TestBool(t *testing.T) {
	t.Parallel()
	wantPath := scope.StrWebsites.FQPathInt64(3, "web/cors/allow_credentials")
	b := model.NewBool("web/cors/allow_credentials", model.WithConfigStructure(configStructure), model.WithSource(source.YesNo))

	assert.Exactly(t, source.YesNo, b.Options())
	// because default value in packageConfiguration is "true"
	assert.True(t, b.Get(config.NewMockGetter().NewScoped(0, 0, 0)))

	assert.False(t, b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: 0,
		}),
	).NewScoped(0, 0, 3)))

	mw := &config.MockWrite{}
	assert.EqualError(t, b.Write(mw, true, scope.StoreID, 3), "Scope permission insufficient: Have 'Store'; Want 'Default,Website'")
	assert.NoError(t, b.Write(mw, true, scope.WebsiteID, 3))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "true", mw.ArgValue.(string))
}
开发者ID:joao-parana,项目名称:csfw,代码行数:21,代码来源:primitives_test.go


示例16: TestBaseURL

func TestBaseURL(t *testing.T) {
	t.Parallel()
	wantPath := scope.StrStores.FQPathInt64(1, "web/unsecure/base_url")
	b := model.NewBaseURL("web/unsecure/base_url", model.WithConfigStructure(configStructure))

	assert.Empty(t, b.Options())

	assert.Exactly(t, "{{base_url}}", b.Get(config.NewMockGetter().NewScoped(0, 0, 1)))

	assert.Exactly(t, "http://cs.io", b.Get(config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "http://cs.io",
		}),
	).NewScoped(0, 0, 1)))

	mw := &config.MockWrite{}
	assert.NoError(t, b.Write(mw, "dude", scope.StoreID, 1))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, "dude", mw.ArgValue.(string))

}
开发者ID:joao-parana,项目名称:csfw,代码行数:21,代码来源:web_test.go


示例17: TestBasePathString

func TestBasePathString(t *testing.T) {
	t.Parallel()
	const path = "web/cors/exposed_headers"
	p1 := NewPath(path, WithConfigStructure(configStructure))
	assert.Exactly(t, path, p1.String())

	wantPath := scope.StrWebsites.FQPathInt64(2, "web/cors/exposed_headers")
	wantWebsiteID := int64(2) // This number 2 is usually stored in core_website/store_website table in column website_id

	mw := new(config.MockWrite)
	assert.NoError(t, p1.Write(mw, 314159, scope.WebsiteID, wantWebsiteID))
	assert.Exactly(t, wantPath, mw.ArgPath)
	assert.Exactly(t, 314159, mw.ArgValue.(int))

	sg := config.NewMockGetter().NewScoped(wantWebsiteID, 0, 0)
	defaultStr, err := p1.lookupString(sg)
	assert.NoError(t, err)
	assert.Exactly(t, "Content-Type,X-CoreStore-ID", defaultStr)

	sg = config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			wantPath: "X-CoreStore-TOKEN",
		}),
	).NewScoped(wantWebsiteID, 0, 0)

	customStr, err := p1.lookupString(sg)
	assert.NoError(t, err)
	assert.Exactly(t, "X-CoreStore-TOKEN", customStr)

	// now change a default value in the packageConfiguration and see it reflects to p1
	f, err := configStructure.FindFieldByPath(path)
	assert.NoError(t, err)
	f.Default = "Content-Size,Y-CoreStore-ID"

	ws, err := p1.lookupString(config.NewMockGetter().NewScoped(wantWebsiteID, 0, 0))
	assert.NoError(t, err)
	assert.Exactly(t, "Content-Size,Y-CoreStore-ID", ws)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:38,代码来源:base_test.go


示例18: init

func init() {
	middlewareConfigReader = config.NewMockGetter(
		config.WithMockValues(config.MockPV{
			scope.StrDefault.FQPathInt64(0, backend.Backend.WebURLRedirectToBase.String()):  1,
			scope.StrStores.FQPathInt64(1, backend.Backend.WebSecureUseInFrontend.String()): true,
			scope.StrStores.FQPathInt64(1, backend.Backend.WebUnsecureBaseURL.String()):     "http://www.corestore.io/",
			scope.StrStores.FQPathInt64(1, backend.Backend.WebSecureBaseURL.String()):       "https://www.corestore.io/",
		}),
	)

	middlewareCtxStoreService = storemock.WithContextMustService(
		scope.Option{},
		func(ms *storemock.Storage) {
			ms.MockStore = func() (*store.Store, error) {
				return store.NewStore(
					&store.TableStore{StoreID: 1, Code: dbr.NewNullString("de"), WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true},
					&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
					&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
					store.WithStoreConfig(middlewareConfigReader),
				)
			}
		},
	)
}
开发者ID:joao-parana,项目名称:csfw,代码行数:24,代码来源:middleware_test.go


示例19: init

func init() {
	middlewareConfigReader = config.NewMockReader(
		config.WithMockValues(config.MockPV{
			config.MockPathScopeDefault(store.PathRedirectToBase):    1,
			config.MockPathScopeStore(1, store.PathSecureInFrontend): true,
			config.MockPathScopeStore(1, store.PathUnsecureBaseURL):  "http://www.corestore.io/",
			config.MockPathScopeStore(1, store.PathSecureBaseURL):    "https://www.corestore.io/",
		}),
	)

	middlewareCtxStoreService = storemock.NewContextService(
		scope.Option{},
		func(ms *storemock.Storage) {
			ms.MockStore = func() (*store.Store, error) {
				return store.NewStore(
					&store.TableStore{StoreID: 1, Code: dbr.NewNullString("de"), WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true},
					&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
					&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
					store.SetStoreConfig(middlewareConfigReader),
				)
			}
		},
	)
}
开发者ID:levcom,项目名称:csfw,代码行数:24,代码来源:middleware_test.go


示例20: TestHTTPRateLimitConfig

func TestHTTPRateLimitConfig(t *testing.T) {
	cr := config.NewMockReader(
		config.WithMockValues(config.MockPV{
			config.MockPathScopeDefault(ctxthrottled.PathRateLimitBurst):    0,
			config.MockPathScopeDefault(ctxthrottled.PathRateLimitRequests): 1,
			config.MockPathScopeDefault(ctxthrottled.PathRateLimitDuration): "i",
		}),
	)

	limiter := ctxthrottled.HTTPRateLimit{
		Config: cr,
		VaryBy: &pathGetter{},
	}

	handler := limiter.WithRateLimit(nil, ctxhttp.HandlerFunc(func(_ context.Context, w http.ResponseWriter, _ *http.Request) error {
		w.WriteHeader(200)
		return nil
	}))

	runHTTPTestCases(t, handler, []httpTestCase{
		{"xx", 200, map[string]string{"X-Ratelimit-Limit": "1", "X-Ratelimit-Remaining": "0", "X-Ratelimit-Reset": "60"}},
		{"xx", 429, map[string]string{"X-Ratelimit-Limit": "1", "X-Ratelimit-Remaining": "0", "X-Ratelimit-Reset": "60", "Retry-After": "60"}},
	})
}
开发者ID:levcom,项目名称:csfw,代码行数:24,代码来源:http_test.go



注:本文中的github.com/corestoreio/csfw/config.WithMockValues函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang config.GroupSlice类代码示例发布时间:2022-05-23
下一篇:
Golang config.ScopeStore函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap