golang.org/x/build@v0.0.0-20240506185731-218518f32b70/internal/task/dlcl_test.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package task 6 7 import ( 8 "bytes" 9 "context" 10 "fmt" 11 "testing" 12 "time" 13 14 "github.com/google/go-cmp/cmp" 15 "golang.org/x/build/internal/workflow" 16 ) 17 18 func TestMailDLCL(t *testing.T) { 19 year := fmt.Sprint(time.Now().UTC().Year()) 20 tests := [...]struct { 21 name string 22 kind ReleaseKind 23 major int 24 version string 25 wantLog string 26 }{ 27 { 28 name: "minor", 29 kind: KindMinor, 30 major: 17, 31 version: "go1.17.1", 32 wantLog: `file "go1.17.1/main.go" (command "golang.org/dl/go1.17.1"): 33 // Copyright ` + year + ` The Go Authors. All rights reserved. 34 // Use of this source code is governed by a BSD-style 35 // license that can be found in the LICENSE file. 36 37 // The go1.17.1 command runs the go command from Go 1.17.1. 38 // 39 // To install, run: 40 // 41 // $ go install golang.org/dl/go1.17.1@latest 42 // $ go1.17.1 download 43 // 44 // And then use the go1.17.1 command as if it were your normal go 45 // command. 46 // 47 // See the release notes at https://go.dev/doc/devel/release#go1.17.1. 48 // 49 // File bugs at https://go.dev/issue/new. 50 package main 51 52 import "golang.org/dl/internal/version" 53 54 func main() { 55 version.Run("go1.17.1") 56 }` + "\n", 57 }, 58 { 59 name: "beta", 60 kind: KindBeta, 61 major: 17, 62 version: "go1.17beta1", 63 wantLog: `file "go1.17beta1/main.go" (command "golang.org/dl/go1.17beta1"): 64 // Copyright ` + year + ` The Go Authors. All rights reserved. 65 // Use of this source code is governed by a BSD-style 66 // license that can be found in the LICENSE file. 67 68 // The go1.17beta1 command runs the go command from Go 1.17beta1. 69 // 70 // To install, run: 71 // 72 // $ go install golang.org/dl/go1.17beta1@latest 73 // $ go1.17beta1 download 74 // 75 // And then use the go1.17beta1 command as if it were your normal go 76 // command. 77 // 78 // See the release notes at https://tip.golang.org/doc/go1.17. 79 // 80 // File bugs at https://go.dev/issue/new. 81 package main 82 83 import "golang.org/dl/internal/version" 84 85 func main() { 86 version.Run("go1.17beta1") 87 }` + "\n", 88 }, 89 { 90 name: "rc", 91 kind: KindRC, 92 major: 17, 93 version: "go1.17rc2", 94 wantLog: `file "go1.17rc2/main.go" (command "golang.org/dl/go1.17rc2"): 95 // Copyright ` + year + ` The Go Authors. All rights reserved. 96 // Use of this source code is governed by a BSD-style 97 // license that can be found in the LICENSE file. 98 99 // The go1.17rc2 command runs the go command from Go 1.17rc2. 100 // 101 // To install, run: 102 // 103 // $ go install golang.org/dl/go1.17rc2@latest 104 // $ go1.17rc2 download 105 // 106 // And then use the go1.17rc2 command as if it were your normal go 107 // command. 108 // 109 // See the release notes at https://tip.golang.org/doc/go1.17. 110 // 111 // File bugs at https://go.dev/issue/new. 112 package main 113 114 import "golang.org/dl/internal/version" 115 116 func main() { 117 version.Run("go1.17rc2") 118 }` + "\n", 119 }, 120 { 121 name: "major", 122 kind: KindMajor, 123 major: 21, 124 version: "go1.21.0", 125 wantLog: `file "go1.21.0/main.go" (command "golang.org/dl/go1.21.0"): 126 // Copyright ` + year + ` The Go Authors. All rights reserved. 127 // Use of this source code is governed by a BSD-style 128 // license that can be found in the LICENSE file. 129 130 // The go1.21.0 command runs the go command from Go 1.21.0. 131 // 132 // To install, run: 133 // 134 // $ go install golang.org/dl/go1.21.0@latest 135 // $ go1.21.0 download 136 // 137 // And then use the go1.21.0 command as if it were your normal go 138 // command. 139 // 140 // See the release notes at https://go.dev/doc/go1.21. 141 // 142 // File bugs at https://go.dev/issue/new. 143 package main 144 145 import "golang.org/dl/internal/version" 146 147 func main() { 148 version.Run("go1.21.0") 149 }` + "\n", 150 }, 151 } 152 for _, tc := range tests { 153 t.Run(tc.name, func(t *testing.T) { 154 // Call the mail a dl CL task function in dry-run mode so it 155 // doesn't actually try to mail a dl CL, but capture its log. 156 var buf bytes.Buffer 157 ctx := &workflow.TaskContext{Context: context.Background(), Logger: fmtWriter{&buf}} 158 tasks := &VersionTasks{Gerrit: nil} 159 changeID, err := tasks.MailDLCL(ctx, tc.major, tc.kind, tc.version, nil, true) 160 if err != nil { 161 t.Fatal("got a non-nil error:", err) 162 } 163 if got, want := changeID, "(dry-run)"; got != want { 164 t.Errorf("unexpected changeID: got = %q, want %q", got, want) 165 } 166 if diff := cmp.Diff(tc.wantLog, buf.String()); diff != "" { 167 t.Errorf("log mismatch (-want +got):\n%s", diff) 168 } 169 }) 170 } 171 }