| // Copyright 2024 The Go Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style | |
| // license that can be found in the LICENSE file. | |
| package task | |
| import ( | |
| "context" | |
| "testing" | |
| "testing/synctest" | |
| "golang.org/x/build/internal/workflow" | |
| "golang.org/x/build/internal/workflowtest" | |
| ) | |
| func TestPromoteNextAPIAndOpenAPIAuditIssue(t *testing.T) { | |
| synctest.Test(t, func(t *testing.T) { | |
| goRepo := NewFakeRepo(t, "go") | |
| goRepo.Commit(map[string]string{ | |
| "api/next/54386.txt": "pkg bytes, func ContainsFunc([]uint8, func(int32) bool) bool #54386\n", | |
| "api/next/53685.txt": "pkg bytes, method (*Buffer) AvailableBuffer() []uint8 #53685\npkg bytes, method (*Buffer) Available() int #53685\n", | |
| "api/next/59488.txt": "pkg cmp, func Compare[$0 Ordered]($0, $0) int #59488\npkg cmp, func Less[$0 Ordered]($0, $0) bool #59488\npkg cmp, type Ordered interface {} #59488\n", | |
| "api/next/50489.txt": "pkg math/big, method (*Rat) FloatPrec() (int, bool) #50489\n", | |
| }) | |
| fakeGerrit := NewFakeGerrit(t, goRepo) | |
| fakeGitHub := &FakeGitHub{ | |
| Milestones: map[int]string{322: "Go1.24"}, // https://github.com/golang/go/milestone/322 | |
| } | |
| const version = 24 | |
| cycleTasks := ReleaseCycleTasks{ | |
| Gerrit: fakeGerrit, | |
| GitHub: fakeGitHub, | |
| } | |
| promotedAPI, err := cycleTasks.PromoteNextAPI( | |
| &workflow.TaskContext{Context: context.Background(), Logger: &workflowtest.Logger{T: t}}, | |
| version, | |
| nil, | |
| ) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| apiAuditIssue, err := cycleTasks.OpenAPIAuditIssue( | |
| &workflow.TaskContext{Context: context.Background(), Logger: &workflowtest.Logger{T: t}}, | |
| version, | |
| RelnoteTracking{Milestone: 322}, | |
| promotedAPI, | |
| ) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| const wantIssueTitle = "api: audit for Go 1.24" | |
| const wantIssueBody = `This is a tracking issue for doing an audit of API additions for Go 1.24 as of [CL 1](https://go.dev/cl/1). | |
| ## New API changes for Go 1.24 | |
| ### bytes | |
| - ` + "`" + `func ContainsFunc([]uint8, func(int32) bool) bool` + "`" + ` #54386 | |
| - ` + "`" + `method (*Buffer) Available() int` + "`" + ` #53685 | |
| - ` + "`" + `method (*Buffer) AvailableBuffer() []uint8` + "`" + ` #53685 | |
| ### cmp | |
| - ` + "`" + `func Compare[$0 Ordered]($0, $0) int` + "`" + ` #59488 | |
| - ` + "`" + `func Less[$0 Ordered]($0, $0) bool` + "`" + ` #59488 | |
| - ` + "`" + `type Ordered interface {}` + "`" + ` #59488 | |
| ### math/big | |
| - ` + "`" + `method (*Rat) FloatPrec() (int, bool)` + "`" + ` #50489 | |
| CC @aclements, @ianlancetaylor, @golang/release.` | |
| if len(fakeGitHub.Issues) != 1 { | |
| t.Fatalf("created %d issues, want 1", len(fakeGitHub.Issues)) | |
| } | |
| if got, want := fakeGitHub.Issues[apiAuditIssue].GetTitle(), wantIssueTitle; got != want { | |
| t.Errorf("issue title mismatch: got %s, want %s", got, want) | |
| } | |
| if got, want := fakeGitHub.Issues[apiAuditIssue].GetBody(), wantIssueBody; got != want { | |
| t.Errorf("issue body mismatch: got %s, want %s", got, want) | |
| } | |
| }) | |
| } | |
| func TestPromoteNextAPIAlreadyExists(t *testing.T) { | |
| synctest.Test(t, func(t *testing.T) { | |
| newAPILine := "pkg bytes, func ContainsFunc([]uint8, func(int32) bool) bool #54386" | |
| goRepo := NewFakeRepo(t, "go") | |
| goRepo.Commit(map[string]string{ | |
| "api/go1.24.txt": newAPILine + "\n", | |
| }) | |
| fakeGerrit := NewFakeGerrit(t, goRepo) | |
| const version = 24 | |
| approved := false | |
| cycleTasks := ReleaseCycleTasks{ | |
| Gerrit: fakeGerrit, | |
| ApproveAction: func(tc *workflow.TaskContext) error { | |
| approved = true | |
| return nil | |
| }, | |
| } | |
| promotedAPI, err := cycleTasks.PromoteNextAPI( | |
| &workflow.TaskContext{Context: context.Background(), Logger: &workflowtest.Logger{T: t}}, | |
| version, | |
| nil, | |
| ) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| if !approved { | |
| t.Error("expected ApproveAction to have executed on retry, but it did not") | |
| } | |
| if len(promotedAPI.APIs) != 1 || promotedAPI.APIs[0] != newAPILine { | |
| t.Fatalf("unexpected promoted APIs: want []string{%s}, got %+v", newAPILine, promotedAPI.APIs) | |
| } | |
| }) | |
| } |