MCPcopy Create free account
hub / github.com/bluekeyes/patch2pr / runGraphQLPatchTest

Function runGraphQLPatchTest

graphql_applier_test.go:43–94  ·  view source on GitHub ↗
(t *testing.T, tctx *TestContext, name string)

Source from the content-addressed store, hash-verified

41}
42
43func runGraphQLPatchTest(t *testing.T, tctx *TestContext, name string) {
44 f, err := os.Open(filepath.Join("testdata", "patches", name+".patch"))
45 if err != nil {
46 t.Fatalf("error opening patch file: %v", err)
47 }
48 defer f.Close()
49
50 files, _, err := gitdiff.Parse(f)
51 if err != nil {
52 t.Fatalf("error parsing patch: %v", err)
53 }
54
55 applier := NewGraphQLApplier(tctx.V4Client, tctx.Repo, tctx.BaseCommit.GetSHA())
56 applier.SetV3Client(tctx.Client)
57
58 unsupported := false
59 for _, file := range files {
60 if err := applier.Apply(tctx, file); err != nil {
61 if GraphQLUnsupportedPatches[name] && IsUnsupported(err) {
62 unsupported = true
63 continue
64 }
65 t.Fatalf("error applying file patch: %s: %v", file.NewName, err)
66 }
67 }
68 if unsupported {
69 return
70 }
71 if GraphQLUnsupportedPatches[name] {
72 t.Fatalf("patch is unsupported, but Apply did not return an error")
73 }
74
75 // GraphQL applies require that the target branch already exists
76 ref := NewReference(tctx.Client, tctx.Repo, tctx.Branch(name))
77 if err := ref.Set(tctx, tctx.BaseCommit.GetSHA(), true); err != nil {
78 t.Fatalf("error creating ref: %v", err)
79 }
80
81 sha, err := applier.Commit(tctx, tctx.Branch(name), &gitdiff.PatchHeader{
82 Title: name,
83 })
84 if err != nil {
85 t.Fatalf("error committing changes: %v", err)
86 }
87
88 commit, _, err := tctx.Client.Git.GetCommit(tctx, tctx.Repo.Owner, tctx.Repo.Name, sha)
89 if err != nil {
90 t.Fatalf("error getting new commit: %v", err)
91 }
92
93 assertPatchResult(t, tctx, name, commit)
94}

Callers 1

TestGraphQLApplierFunction · 0.85

Calls 9

SetV3ClientMethod · 0.95
ApplyMethod · 0.95
SetMethod · 0.95
CommitMethod · 0.95
NewGraphQLApplierFunction · 0.85
IsUnsupportedFunction · 0.85
NewReferenceFunction · 0.85
assertPatchResultFunction · 0.85
BranchMethod · 0.80

Tested by

no test coverage detected