Skip to content

Commit c954c37

Browse files
authored
Move Git e2e helpers to test/utils package (#29)
1 parent e28082f commit c954c37

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

test/e2e/bundle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func createNamespaceAndDeployFunction() TestNamespace {
381381
DeferCleanup(cleanup)
382382

383383
// Initialize repo with function code
384-
repoDir, err := InitializeRepoWithFunction(repoURL, username, password, "go")
384+
repoDir, err := utils.InitializeRepoWithFunction(repoURL, username, password, "go")
385385
Expect(err).NotTo(HaveOccurred())
386386
DeferCleanup(os.RemoveAll, repoDir)
387387

test/e2e/func_deploy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var _ = Describe("Operator", func() {
5454
DeferCleanup(cleanup)
5555

5656
// Initialize repository with function code
57-
repoDir, err = InitializeRepoWithFunction(repoURL, username, password, "go")
57+
repoDir, err = utils.InitializeRepoWithFunction(repoURL, username, password, "go")
5858
Expect(err).NotTo(HaveOccurred())
5959
DeferCleanup(os.RemoveAll, repoDir)
6060

@@ -79,7 +79,7 @@ var _ = Describe("Operator", func() {
7979
})
8080

8181
// Commit func.yaml changes
82-
err = CommitAndPush(repoDir, "Update func.yaml after deploy", "func.yaml")
82+
err = utils.CommitAndPush(repoDir, "Update func.yaml after deploy", "func.yaml")
8383
Expect(err).NotTo(HaveOccurred())
8484
})
8585

@@ -173,7 +173,7 @@ var _ = Describe("Operator", func() {
173173
DeferCleanup(cleanup)
174174

175175
// Initialize repository with function code
176-
repoDir, err = InitializeRepoWithFunction(repoURL, username, password, "go")
176+
repoDir, err = utils.InitializeRepoWithFunction(repoURL, username, password, "go")
177177
Expect(err).NotTo(HaveOccurred())
178178
DeferCleanup(os.RemoveAll, repoDir)
179179

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package e2e
17+
package utils
1818

1919
import (
2020
"fmt"
2121
"os"
2222
"os/exec"
2323
"strings"
2424

25-
"github.com/functions-dev/func-operator/test/utils"
2625
"k8s.io/apimachinery/pkg/util/rand"
2726
)
2827

@@ -41,43 +40,43 @@ func InitializeRepoWithFunction(repoURL, username, password, language string) (r
4140

4241
// Initialize function (func init creates the directory)
4342
cmd := exec.Command("func", "init", "-l", language, repoDir)
44-
if _, err = utils.Run(cmd); err != nil {
43+
if _, err = Run(cmd); err != nil {
4544
return "", fmt.Errorf("failed to init function: %w", err)
4645
}
4746

4847
// Initialize git repo with main as default branch
4948
cmd = exec.Command("git", "-C", repoDir, "init", "-b", "main")
50-
if _, err = utils.Run(cmd); err != nil {
49+
if _, err = Run(cmd); err != nil {
5150
return "", fmt.Errorf("failed to git init: %w", err)
5251
}
5352

5453
// Configure git user
5554
cmd = exec.Command("git", "-C", repoDir, "config", "user.name", "Test User")
56-
if _, err = utils.Run(cmd); err != nil {
55+
if _, err = Run(cmd); err != nil {
5756
return "", fmt.Errorf("failed to set git user.name: %w", err)
5857
}
5958
cmd = exec.Command("git", "-C", repoDir, "config", "user.email", "test@example.com")
60-
if _, err = utils.Run(cmd); err != nil {
59+
if _, err = Run(cmd); err != nil {
6160
return "", fmt.Errorf("failed to set git user.email: %w", err)
6261
}
6362

6463
// Add remote
6564
cmd = exec.Command("git", "-C", repoDir, "remote", "add", "origin", authURL)
66-
if _, err = utils.Run(cmd); err != nil {
65+
if _, err = Run(cmd); err != nil {
6766
return "", fmt.Errorf("failed to add remote: %w", err)
6867
}
6968

7069
// Commit and push
7170
cmd = exec.Command("git", "-C", repoDir, "add", ".")
72-
if _, err = utils.Run(cmd); err != nil {
71+
if _, err = Run(cmd); err != nil {
7372
return "", fmt.Errorf("failed to git add: %w", err)
7473
}
7574
cmd = exec.Command("git", "-C", repoDir, "commit", "-m", "Initial function")
76-
if _, err = utils.Run(cmd); err != nil {
75+
if _, err = Run(cmd); err != nil {
7776
return "", fmt.Errorf("failed to git commit: %w", err)
7877
}
7978
cmd = exec.Command("git", "-C", repoDir, "push", "-u", "origin", "main")
80-
if _, err = utils.Run(cmd); err != nil {
79+
if _, err = Run(cmd); err != nil {
8180
return "", fmt.Errorf("failed to push initial commit: %w", err)
8281
}
8382

@@ -89,27 +88,27 @@ func InitializeRepoWithFunction(repoURL, username, password, language string) (r
8988
func CommitAndPush(repoDir string, msg string, file string, otherFiles ...string) error {
9089
// Add first file
9190
cmd := exec.Command("git", "-C", repoDir, "add", file)
92-
if _, err := utils.Run(cmd); err != nil {
91+
if _, err := Run(cmd); err != nil {
9392
return fmt.Errorf("failed to git add %s: %w", file, err)
9493
}
9594

9695
// Add other files if provided
9796
for _, f := range otherFiles {
9897
cmd = exec.Command("git", "-C", repoDir, "add", f)
99-
if _, err := utils.Run(cmd); err != nil {
98+
if _, err := Run(cmd); err != nil {
10099
return fmt.Errorf("failed to git add %s: %w", f, err)
101100
}
102101
}
103102

104103
// Commit
105104
cmd = exec.Command("git", "-C", repoDir, "commit", "-m", msg)
106-
if _, err := utils.Run(cmd); err != nil {
105+
if _, err := Run(cmd); err != nil {
107106
return fmt.Errorf("failed to git commit: %w", err)
108107
}
109108

110109
// Push
111110
cmd = exec.Command("git", "-C", repoDir, "push")
112-
if _, err := utils.Run(cmd); err != nil {
111+
if _, err := Run(cmd); err != nil {
113112
return fmt.Errorf("failed to push: %w", err)
114113
}
115114

0 commit comments

Comments
 (0)