예제 #1
0
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))
}
예제 #2
0
func TestRecursiveOption(t *testing.T) {
	t.Parallel()
	b := model.NewInt(
		"web/cors/int",
		model.WithConfigStructure(configStructure),
		model.WithSourceByString("a", "A", "b", "b"),
	)

	assert.Exactly(t, source.NewByString("a", "A", "b", "b"), b.Source)

	previous := b.Option(model.WithSourceByString(
		"1", "One", "2", "Two",
	))
	assert.Exactly(t, source.NewByString("1", "One", "2", "Two"), b.Source)

	b.Option(previous)
	assert.Exactly(t, source.NewByString("a", "A", "b", "b"), b.Source)
}
예제 #3
0
// initSourceCountry should run every time your service initializes or
// a value in the database changes.
func initSourceCountry(dbrsess dbr.SessionRunner, o *PkgSource) error {
	Backend.Lock()
	defer Backend.Unlock()

	// o.Country
	// TODO load from database the iso code and as value the names
	o.Country = source.NewByString("AU", "Australia", "FI", "Finland", "DE", "Germany")

	// apply the list of country codes to:
	Backend.GeneralCountryDefault.Source = o.Country
	Backend.GeneralCountryAllow.Source = o.Country
	Backend.GeneralCountryOptionalZipCountries.Source = o.Country
	Backend.GeneralCountryEuCountries.Source = o.Country
	Backend.GeneralCountryDestinations.Source = o.Country
	return nil
}