golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/quic/files_test.go (about)

     1  // Copyright 2023 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  //go:build go1.21
     6  
     7  package quic
     8  
     9  import (
    10  	"bytes"
    11  	"os"
    12  	"strings"
    13  	"testing"
    14  )
    15  
    16  // TestFiles checks that every file in this package has a build constraint on Go 1.21.
    17  //
    18  // The QUIC implementation depends on crypto/tls features added in Go 1.21,
    19  // so there's no point in trying to build on anything older.
    20  //
    21  // Drop this test when the x/net go.mod depends on 1.21 or newer.
    22  func TestFiles(t *testing.T) {
    23  	f, err := os.Open(".")
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  	names, err := f.Readdirnames(-1)
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	for _, name := range names {
    32  		if !strings.HasSuffix(name, ".go") {
    33  			continue
    34  		}
    35  		b, err := os.ReadFile(name)
    36  		if err != nil {
    37  			t.Fatal(err)
    38  		}
    39  		// Check for copyright header while we're in here.
    40  		if !bytes.Contains(b, []byte("The Go Authors.")) {
    41  			t.Errorf("%v: missing copyright", name)
    42  		}
    43  		// doc.go doesn't need a build constraint.
    44  		if name == "doc.go" {
    45  			continue
    46  		}
    47  		if !bytes.Contains(b, []byte("//go:build go1.21")) {
    48  			t.Errorf("%v: missing constraint on go1.21", name)
    49  		}
    50  	}
    51  }