This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework e2e tests for logstream instrumentation and to be more similar…
… to Pipeline's e2e tests Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
- Loading branch information
Showing
24 changed files
with
1,914 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
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 names | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
utilrand "k8s.io/apimachinery/pkg/util/rand" | ||
) | ||
|
||
// NameGenerator generates names for objects. Some backends may have more information | ||
// available to guide selection of new names and this interface hides those details. | ||
type NameGenerator interface { | ||
// RestrictLengthWithRandomSuffix generates a valid name from the base name, adding a random suffix to the | ||
// the base. If base is valid, the returned name must also be valid. The generator is | ||
// responsible for knowing the maximum valid name length. | ||
RestrictLengthWithRandomSuffix(base string) string | ||
|
||
// RestrictLength generates a valid name from the name of a step specified in a Task, | ||
// shortening it to the maximum valid name length if needed. | ||
RestrictLength(base string) string | ||
} | ||
|
||
// simpleNameGenerator generates random names. | ||
type simpleNameGenerator struct{} | ||
|
||
// SimpleNameGenerator is a generator that returns the name plus a random suffix of five alphanumerics | ||
// when a name is requested. The string is guaranteed to not exceed the length of a standard Kubernetes | ||
// name (63 characters) | ||
var SimpleNameGenerator NameGenerator = simpleNameGenerator{} | ||
|
||
const ( | ||
// TODO: make this flexible for non-core resources with alternate naming rules. | ||
maxNameLength = 63 | ||
randomLength = 5 | ||
maxGeneratedNameLength = maxNameLength - randomLength - 1 | ||
) | ||
|
||
// RestrictLengthWithRandomSuffix takes a base name and returns a potentially shortened version of that name with | ||
// a random suffix, with the whole string no longer than 63 characters. | ||
func (simpleNameGenerator) RestrictLengthWithRandomSuffix(base string) string { | ||
if len(base) > maxGeneratedNameLength { | ||
base = base[:maxGeneratedNameLength] | ||
} | ||
return fmt.Sprintf("%s-%s", base, utilrand.String(randomLength)) | ||
} | ||
|
||
var alphaNumericRE = regexp.MustCompile(`^[a-zA-Z0-9]+$`) | ||
|
||
// RestrictLength takes a base name and returns a potentially shortened version of that name, no longer than 63 characters. | ||
func (simpleNameGenerator) RestrictLength(base string) string { | ||
if len(base) > maxNameLength { | ||
base = base[:maxNameLength] | ||
} | ||
|
||
for !alphaNumericRE.MatchString(base[len(base)-1:]) { | ||
base = base[:len(base)-1] | ||
} | ||
return base | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2022 The Tekton Authors | ||
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 names | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/tektoncd/resolution/test/names" | ||
) | ||
|
||
func TestRestrictLengthWithRandomSuffix(t *testing.T) { | ||
for _, c := range []struct { | ||
in, want string | ||
}{{ | ||
in: "hello", | ||
want: "hello-9l9zj", | ||
}, { | ||
in: strings.Repeat("a", 100), | ||
want: strings.Repeat("a", 57) + "-9l9zj", | ||
}} { | ||
t.Run(c.in, func(t *testing.T) { | ||
names.TestingSeed() | ||
got := SimpleNameGenerator.RestrictLengthWithRandomSuffix(c.in) | ||
if got != c.want { | ||
t.Errorf("RestrictLengthWithRandomSuffix:\n got %q\nwant %q", got, c.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestRestrictLength(t *testing.T) { | ||
for _, c := range []struct { | ||
in, want string | ||
}{{ | ||
in: "hello", | ||
want: "hello", | ||
}, { | ||
in: strings.Repeat("a", 100), | ||
want: strings.Repeat("a", maxNameLength), | ||
}, { | ||
// Values that don't end with an alphanumeric value are | ||
// trimmed until they do. | ||
in: "abcdefg !@#!$", | ||
want: "abcdefg", | ||
}} { | ||
t.Run(c.in, func(t *testing.T) { | ||
got := SimpleNameGenerator.RestrictLength(c.in) | ||
if got != c.want { | ||
t.Errorf("RestrictLength:\n got %q\nwant %q", got, c.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//go:build e2e | ||
|
||
/* | ||
Copyright 2022 The Tekton Authors | ||
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 test | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/tektoncd/resolution/pkg/apis/resolution/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
knativetest "knative.dev/pkg/test" | ||
"knative.dev/pkg/test/helpers" | ||
) | ||
|
||
// waitInterval is the duration between repeat attempts to check on the | ||
// status of the test's resolution request. | ||
const waitInterval = time.Second | ||
|
||
// waitTimeout is the total maximum time the test may spend waiting for | ||
// successful resolution of the test's bundle request. | ||
const waitTimeout = 20 * time.Second | ||
|
||
// TestBundlesSmoke creates a resolution request for a bundle and checks | ||
// that it succeeds. | ||
func TestBundlesSmoke(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
requestYAML, err := os.ReadFile("./bundles_test/resolution-request.yaml") | ||
if err != nil { | ||
t.Fatalf("unable to read resolution request yaml fixture: %v", err) | ||
} | ||
|
||
req := &v1alpha1.ResolutionRequest{} | ||
_, _, err = scheme.Codecs.UniversalDeserializer().Decode(requestYAML, nil, req) | ||
if err != nil { | ||
t.Fatalf("error parsing resolution request yaml fixture: %v", err) | ||
} | ||
req.Name = helpers.ObjectNameForTest(t) | ||
|
||
c, ns := setup(ctx, t) | ||
knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, ns) }, t.Logf) | ||
defer tearDown(ctx, t, c, ns) | ||
|
||
_, err = c.ResolutionRequestClient.Create(ctx, req, metav1.CreateOptions{}) | ||
if err != nil { | ||
t.Fatalf("error creating request: %v", err) | ||
} | ||
|
||
err = wait.PollImmediate(waitInterval, waitTimeout, func() (bool, error) { | ||
latestResolutionRequest, err := c.ResolutionRequestClient.Get(ctx, req.Name, metav1.GetOptions{}) | ||
if err != nil { | ||
return false, err | ||
} | ||
resolvedData := latestResolutionRequest.Status.ResolutionRequestStatusFields.Data | ||
if resolvedData != "" { | ||
return true, nil | ||
} | ||
return false, nil | ||
}) | ||
|
||
if err != nil { | ||
t.Fatalf("error waiting for completed resolution request: %v", err) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.