Skip to content

Commit

Permalink
Merge pull request kubernetes#26562 from listx/refactor
Browse files Browse the repository at this point in the history
refactor and add more logging for fakegitserver
  • Loading branch information
k8s-ci-robot authored Jun 13, 2022
2 parents b65f79c + 235daab commit e739eaf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
5 changes: 5 additions & 0 deletions prow/test/integration/internal/fakegitserver/fakegitserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ func setupRepo(gitReposParentDir string, repoSetup *RepoSetup) (*git.Repository,
return nil, err
}

logger.Infof("successfully ran setup script in %s", dir)

if err := convertToBareRepo(repo, dir); err != nil {
logger.Error("conversion to bare repo failed")
return nil, err
Expand Down Expand Up @@ -275,6 +277,9 @@ func runSetupScript(repoPath, script string) error {
cmd := exec.Command("sh", "-c", script)
cmd.Dir = repoPath

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

// By default, make it so that the git commands contained in the script
// result in reproducible commits. This can be overridden by the script
// itself if it chooses to (re-)export the same environment variables.
Expand Down
8 changes: 4 additions & 4 deletions prow/test/integration/internal/fakepubsub/fakepubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type Client struct {
}

func NewClient(projectID, pubsubEmulatorHost string) (*Client, error) {
client, err := newClientOnEmulator(projectID, pubsubEmulatorHost)
client, err := newClientForEmulator(projectID, pubsubEmulatorHost)
if err != nil {
return nil, fmt.Errorf("Unable to create pubsub client to project %q: %v", projectID, err)
return nil, fmt.Errorf("Unable to create pubsub client to project %q for the emulator: %v", projectID, err)
}

return &Client{
Expand All @@ -53,14 +53,14 @@ func NewClient(projectID, pubsubEmulatorHost string) (*Client, error) {
}, nil
}

// newClientOnEmulator returns a pubsub client that is hardcoded to always talk
// newClientForEmulator returns a pubsub client that is hardcoded to always talk
// to the fakepubsub service running in the test KIND cluster via the
// pubsubEmulatorHost parameter. This is taken from
// https://github.com/googleapis/google-cloud-go/blob/e43c095c94e44a95c618861f9da8f2469b53be16/pubsub/pubsub.go#L126.
// This is better than getting the PUBSUB_EMULATOR_HOST environment variable
// because this makes the code thread-safe (we no longer rely on a global
// environment variable).
func newClientOnEmulator(projectID, pubsubEmulatorHost string) (*pubsub.Client, error) {
func newClientForEmulator(projectID, pubsubEmulatorHost string) (*pubsub.Client, error) {
conn, err := grpc.Dial(pubsubEmulatorHost, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, fmt.Errorf("grpc.Dial: %v", err)
Expand Down
17 changes: 8 additions & 9 deletions prow/test/integration/test/sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ import (
func TestPubSubSubscriptions(t *testing.T) {
t.Parallel()

createRepoRepo1 := `
echo this-is-from-repo1 > README.txt
git add README.txt
git commit -m "commit 1"
`
const (
PubsubEmulatorHost = "localhost:30303"
UidLabel = "integration-test/uid"
Repo1HEADsha = "8c5dc6fe1b5a63200f23a2364011e8270f0f7cd0"
CreateRepoRepo1 = `
echo this-is-from-repo1 > README.txt
git add README.txt
git commit -m "commit 1"
`
)

tests := []struct {
Expand All @@ -55,12 +55,11 @@ git commit -m "commit 1"
expected string
}{
{
// Run a job defined in the static config (not inrepoconfig).
name: "non-inrepoconfig",
name: "staticconfig-postsubmit",
repoSetups: []fakegitserver.RepoSetup{
{
Name: "repo1",
Script: createRepoRepo1,
Script: CreateRepoRepo1,
Overwrite: true,
},
},
Expand Down Expand Up @@ -132,7 +131,7 @@ this-is-from-repo1
// Create a unique test case ID (UID) for this particular test
// invocation. This makes it easier to check from this code whether
// sub actually received the exact same message we just published.
uid := fmt.Sprintf("%s-%s", tt.name, RandomString(t))
uid := RandomString(t)
tt.msg.Data.Labels = make(map[string]string)
tt.msg.Data.Labels[UidLabel] = uid

Expand Down

0 comments on commit e739eaf

Please sign in to comment.