Add test cases for http2rpc (#662)

This commit is contained in:
Hinsteny Hisoka
2023-12-09 18:05:38 +08:00
committed by GitHub
parent 17794cef2a
commit 4426f18a84
8 changed files with 314 additions and 10 deletions

View File

@@ -179,6 +179,39 @@ func (a Applier) MustApplyWithCleanup(t *testing.T, c client.Client, timeoutConf
}
}
// MustDelete delete Kubernetes resources defined with the provided YAML file .
func (a Applier) MustDelete(t *testing.T, c client.Client, timeoutConfig config.TimeoutConfig, location string) {
data, err := getContentsFromPathOrURL(location, timeoutConfig)
require.NoError(t, err)
decoder := yaml.NewYAMLOrJSONDecoder(data, 4096)
resources, err := a.prepareResources(t, decoder)
if err != nil {
t.Logf("🧳 Manifest: %s", data.String())
require.NoErrorf(t, err, "error parsing manifest")
}
for i := range resources {
uObj := &resources[i]
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.CreateTimeout)
defer cancel()
// namespacedName := types.NamespacedName{Namespace: uObj.GetNamespace(), Name: uObj.GetName()}
// err := c.Get(ctx, namespacedName, uObj)
// if err != nil {
// if !apierrors.IsNotFound(err) {
// require.NoErrorf(t, err, "error getting resource")
// }
// }
t.Logf("🏗 Deleting %s %s %s", uObj.GetName(), uObj.GetKind(), uObj.GetNamespace())
err = c.Delete(ctx, uObj)
require.NoErrorf(t, err, "error delete resource")
}
}
// getContentsFromPathOrURL takes a string that can either be a local file
// path or an https:// URL to YAML manifests and provides the contents.
func getContentsFromPathOrURL(location string, timeoutConfig config.TimeoutConfig) (*bytes.Buffer, error) {

View File

@@ -115,9 +115,9 @@ func New(s Options) *ConformanceTestSuite {
suite.BaseManifests = []string{
"base/manifests.yaml",
"base/consul.yaml",
"base/dubbo.yaml",
"base/eureka.yaml",
"base/nacos.yaml",
"base/dubbo.yaml",
}
}
@@ -179,11 +179,13 @@ type ConformanceTests []ConformanceTest
type ConformanceTest struct {
ShortName string
Description string
PreDeleteRs []string
Manifests []string
Features []SupportedFeature
Slow bool
Parallel bool
Test func(*testing.T, *ConformanceTestSuite)
NotCleanup bool
}
// Run runs an individual tests, applying and cleaning up the required manifests
@@ -208,9 +210,14 @@ func (test *ConformanceTest) Run(t *testing.T, suite *ConformanceTestSuite) {
t.Logf("🔥 Running Conformance Test: %s", test.ShortName)
for _, manifestLocation := range test.PreDeleteRs {
t.Logf("🧳 Applying PreDeleteRs Manifests: %s", manifestLocation)
suite.Applier.MustDelete(t, suite.Client, suite.TimeoutConfig, manifestLocation)
}
for _, manifestLocation := range test.Manifests {
t.Logf("🧳 Applying Manifests: %s", manifestLocation)
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, manifestLocation, true)
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, manifestLocation, !test.NotCleanup)
}
test.Test(t, suite)