Migration and deprecation evidence
Migration and deprecation evidence
A migration is a controlled change to source, dependencies, language settings or toolchain. Start with a baseline that passes, read release notes and deprecated API documentation, make one meaningful change, and rerun behavior tests. A deprecated identifier is discouraged but not necessarily removed. For example, Go 1.16 deprecated io/ioutil in favor of APIs in io and os. ioutil.ReadAll becomes io.ReadAll, and ioutil.ReadFile becomes os.ReadFile. Check behavior and errors rather than assuming a text replacement is always sufficient.
package main
import ( "fmt" "io" "strings")
func main() { b, err := io.ReadAll(strings.NewReader("migration sample")) if err != nil { panic(err) } fmt.Println(string(b))}For small trusted fixtures ReadAll is fine; for untrusted streams impose a size bound. The replacement does not eliminate the need for resource limits. go doc io.ReadAll, go doc io/ioutil.ReadAll and go vet ./... are useful checks, but go vet is not a complete deprecated-API scanner. A symbol in the standard library does not automatically mean a dependency using it has been tested with your minimum toolchain.
Expected output:
migration samplePreserve error behavior
package main
import ( "errors" "fmt" "io")
type broken struct{}
func (broken) Read(p []byte) (int, error) { copy(p, "x"); return 1, errors.New("read failed") }func main() { b, err := io.ReadAll(broken{}) fmt.Println(string(b), err != nil)}ReadAll can return partial bytes and a non-nil error. A migration test should compare both, not just happy-path text. In a release candidate, record go.mod/go.sum changes, effective Go version, test and vet output, artifact metadata and rollback criteria. Use temporary GODEBUG compatibility switches only when documented for the release; plan removal. Rebuild and test rollback artifacts, and consider irreversible schema changes separately. Never suppress security fixes merely to preserve old behavior.
Expected output:
x trueTry it locally
Migrate a bounded local file read to os.ReadFile. In a temporary directory compare content and verify a missing-file error with errors.Is(err, os.ErrNotExist).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Toolchain and compatibility 08: Migration and deprecation evidence
Check the lesson objective before moving on.
What does deprecation mean?
Which migration check is most useful for a reader?