73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
// Copyright 2023 PingCAP, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package loadremotetest
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/fsouza/fake-gcs-server/fakestorage"
|
|
"github.com/pingcap/tidb/pkg/kv"
|
|
"github.com/pingcap/tidb/pkg/testkit"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type mockGCSSuite struct {
|
|
suite.Suite
|
|
|
|
server *fakestorage.Server
|
|
store kv.Storage
|
|
tk *testkit.TestKit
|
|
}
|
|
|
|
var (
|
|
gcsHost = "127.0.0.1"
|
|
gcsPort = uint16(0)
|
|
// for fake gcs server, we must use this endpoint format
|
|
// NOTE: must end with '/'
|
|
gcsEndpointFormat = "http://%s/storage/v1/"
|
|
)
|
|
|
|
func TestLoadRemote(t *testing.T) {
|
|
suite.Run(t, &mockGCSSuite{})
|
|
}
|
|
|
|
func (s *mockGCSSuite) SetupSuite() {
|
|
var err error
|
|
opt := fakestorage.Options{
|
|
Scheme: "http",
|
|
Host: gcsHost,
|
|
Port: gcsPort,
|
|
PublicHost: gcsHost,
|
|
}
|
|
s.server, err = fakestorage.NewServerWithOptions(opt)
|
|
s.Require().NoError(err)
|
|
s.store = testkit.CreateMockStore(s.T())
|
|
s.tk = testkit.NewTestKit(s.T(), s.store)
|
|
}
|
|
|
|
func (s *mockGCSSuite) GetGCSEndpoint() string {
|
|
parsedURL, err := url.Parse(s.server.URL())
|
|
s.NoError(err)
|
|
gcsHost := parsedURL.Host
|
|
gcsEndpoint := fmt.Sprintf(gcsEndpointFormat, gcsHost)
|
|
return gcsEndpoint
|
|
}
|
|
|
|
func (s *mockGCSSuite) TearDownSuite() {
|
|
s.server.Stop()
|
|
}
|