コード例 #1
0
ファイル: source_models_test.go プロジェクト: levcom/csfw
func TestSourceCurrencyAll(t *testing.T) {

	r := config.NewMockReader(
		config.WithMockString(func(path string) (string, error) {
			t.Log(path)
			switch path {
			case config.MockPathScopeStore(1, directory.PathDefaultLocale):
				return "de_CH", nil
			}
			return "Not Found", nil
		}),
	)

	var s scope.MockID = 1

	sca := directory.NewSourceCurrencyAll(config.ModelConstructor{
		ConfigReader: r,
		ScopeStore:   s,
	})

	t.Logf("\n%#v\n", sca.Options())

}
コード例 #2
0
ファイル: store_test.go プロジェクト: levcom/csfw
func TestStoreBaseURLandPath(t *testing.T) {

	s, err := 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("admin"), Name: dbr.NewNullString("Admin"), SortOrder: 0, DefaultGroupID: 0, IsDefault: dbr.NewNullBool(false)},
		&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "Default", RootCategoryID: 0, DefaultStoreID: 1},
	)
	assert.NoError(t, err)
	if s == nil {
		t.Fail()
	}

	tests := []struct {
		haveR        config.Reader
		haveUT       config.URLType
		haveIsSecure bool
		wantBaseUrl  string
		wantPath     string
	}{
		{
			config.NewMockReader(config.WithMockString(
				func(path string) (string, error) {
					switch path {
					case config.MockPathScopeDefault(store.PathSecureBaseURL):
						return "https://corestore.io", nil
					case config.MockPathScopeDefault(store.PathUnsecureBaseURL):
						return "http://corestore.io", nil
					}
					return "", config.ErrKeyNotFound
				},
			)),
			config.URLTypeWeb, true, "https://corestore.io/", "/",
		},
		{
			config.NewMockReader(config.WithMockString(
				func(path string) (string, error) {
					switch path {
					case config.MockPathScopeDefault(store.PathSecureBaseURL):
						return "https://myplatform.io/customer1", nil
					case config.MockPathScopeDefault(store.PathUnsecureBaseURL):
						return "http://myplatform.io/customer1", nil
					}
					return "", config.ErrKeyNotFound
				},
			)),
			config.URLTypeWeb, false, "http://myplatform.io/customer1/", "/customer1/",
		},
		{
			config.NewMockReader(config.WithMockString(
				func(path string) (string, error) {
					switch path {
					case config.MockPathScopeDefault(store.PathSecureBaseURL):
						return store.PlaceholderBaseURL, nil
					case config.MockPathScopeDefault(store.PathUnsecureBaseURL):
						return store.PlaceholderBaseURL, nil
					case config.MockPathScopeDefault(config.PathCSBaseURL):
						return config.CSBaseURL, nil
					}
					return "", config.ErrKeyNotFound
				},
			)),
			config.URLTypeWeb, false, config.CSBaseURL, "/",
		},
	}

	for i, test := range tests {
		s.ApplyOptions(store.SetStoreConfig(test.haveR))
		assert.NotNil(t, s.Config, "Index %d", i)
		baseURL, err := s.BaseURL(test.haveUT, test.haveIsSecure)
		assert.NoError(t, err)
		assert.EqualValues(t, test.wantBaseUrl, baseURL.String())
		assert.EqualValues(t, test.wantPath, s.Path())

		_, err = s.BaseURL(config.URLTypeAbsent, false)
		assert.EqualError(t, err, config.ErrURLCacheCleared.Error())
	}
}
コード例 #3
0
ファイル: daemon_dialer_test.go プロジェクト: levcom/csfw
			return 0
		case "stores/6023/system/smtp/port":
			return 4040
		default:
			return 0
		}
	}),
	config.WithMockString(func(path string) string {
		//		println("string", path)
		switch path {
		case "stores/5015/system/smtp/host":
			return ""
		case "stores/5015/system/smtp/username":
			return ""
		case "stores/6023/system/smtp/host":
			return "smtp.fastmail.com"
		case "stores/6023/system/smtp/username":
			return "2522e71a49e"
		case "stores/6023/system/smtp/password":
			return "9512e71a49f"
		default:
			return ""
		}

	}),
	config.WithMockBool(func(path string) bool {
		return false
	}),
)

func TestDialerPoolDefaultConfig(t *testing.T) {
	dm, err := NewDaemon(
コード例 #4
0
ファイル: mocks_test.go プロジェクト: levcom/csfw
	"io"
	"testing"

	"github.com/corestoreio/csfw/config"
	"github.com/corestoreio/csfw/email"
	"github.com/go-gomail/gomail"
	"github.com/stretchr/testify/assert"
)

var configMock = config.NewMockReader(
	config.WithMockInt(func(path string) int {
		//println("int", path)
		return 25 // Port 25
	}),
	config.WithMockString(func(path string) string {
		//println("string", path)
		return "localhost"
	}),
	config.WithMockBool(func(path string) bool {
		//println("bool", path)
		switch path {
		case "stores/3001/system/smtp/disable":
			return true
		case "stores/4010/system/smtp/disable":
			return false
		default:
			return false
		}
	}),
)

type mockDial struct {