github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/ci/run_tests_clone_test.go (about) 1 package ci 2 3 import ( 4 "context" 5 "os" 6 "strings" 7 "testing" 8 9 "github.com/quickfeed/quickfeed/internal/rand" 10 "github.com/quickfeed/quickfeed/qf" 11 "github.com/quickfeed/quickfeed/scm" 12 ) 13 14 func init() { 15 os.Setenv("QUICKFEED_REPOSITORY_PATH", "$HOME/tmp/courses") 16 } 17 18 func TestCloneAndCopyRunTests(t *testing.T) { 19 qfTestOrg := scm.GetTestOrganization(t) 20 sc, qfUserName := scm.GetTestSCM(t) 21 22 dstDir := t.TempDir() 23 24 course := &qf.Course{ 25 Code: "QF101", 26 ScmOrganizationName: qfTestOrg, 27 } 28 repo := qf.RepoURL{ProviderURL: "github.com", Organization: qfTestOrg} 29 runData := &RunData{ 30 Course: course, 31 Assignment: &qf.Assignment{ 32 Name: "lab1", 33 }, 34 Repo: &qf.Repository{ 35 HTMLURL: repo.StudentRepoURL(qfUserName), 36 RepoType: qf.Repository_USER, 37 }, 38 JobOwner: "muggles", 39 CommitID: rand.String()[:7], 40 } 41 42 ctx := context.Background() 43 clonedAssignmentsRepo, err := sc.Clone(ctx, &scm.CloneOptions{ 44 Organization: course.GetScmOrganizationName(), 45 Repository: qf.AssignmentsRepo, 46 DestDir: course.CloneDir(), 47 }) 48 if err != nil { 49 t.Error(err) 50 } 51 t.Log(clonedAssignmentsRepo) 52 53 clonedTestsRepo, err := sc.Clone(ctx, &scm.CloneOptions{ 54 Organization: course.GetScmOrganizationName(), 55 Repository: qf.TestsRepo, 56 DestDir: course.CloneDir(), 57 }) 58 if err != nil { 59 t.Error(err) 60 } 61 t.Log(clonedTestsRepo) 62 63 if err := runData.clone(ctx, sc, dstDir); err != nil { 64 t.Error(err) 65 } 66 localRunner := Local{} 67 out, err := localRunner.Run(ctx, &Job{ 68 Commands: []string{`ls ` + dstDir}, 69 }) 70 if err != nil { 71 t.Error(err) 72 } 73 for _, s := range []string{qf.TestsRepo, qf.AssignmentsRepo, qf.StudentRepoName(qfUserName)} { 74 if !strings.Contains(out, s) { 75 t.Errorf("expected %q to contain %q", out, s) 76 } 77 } 78 }