You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

75 lines
1.8 KiB

  1. // Copyright 2016 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package cloud
  15. import (
  16. "bytes"
  17. "io/ioutil"
  18. "os"
  19. "path/filepath"
  20. "strings"
  21. "testing"
  22. )
  23. var sentinels = []string{
  24. "Copyright",
  25. "Google",
  26. `Licensed under the Apache License, Version 2.0 (the "License");`,
  27. }
  28. func TestLicense(t *testing.T) {
  29. t.Parallel()
  30. err := filepath.Walk(".", func(path string, fi os.FileInfo, err error) error {
  31. if err != nil {
  32. return err
  33. }
  34. if ext := filepath.Ext(path); ext != ".go" && ext != ".proto" {
  35. return nil
  36. }
  37. if strings.HasSuffix(path, ".pb.go") {
  38. // .pb.go files are generated from the proto files.
  39. // .proto files must have license headers.
  40. return nil
  41. }
  42. if path == "bigtable/cmd/cbt/cbtdoc.go" {
  43. // Automatically generated.
  44. return nil
  45. }
  46. if path == "cmd/go-cloud-debug-agent/internal/debug/elf/elf.go" {
  47. // BSD license, which is compatible, is embedded in the file.
  48. return nil
  49. }
  50. src, err := ioutil.ReadFile(path)
  51. if err != nil {
  52. return nil
  53. }
  54. src = src[:300] // Ensure all of the sentinel values are at the top of the file.
  55. // Find license
  56. for _, sentinel := range sentinels {
  57. if !bytes.Contains(src, []byte(sentinel)) {
  58. t.Errorf("%v: license header not present. want %q", path, sentinel)
  59. return nil
  60. }
  61. }
  62. return nil
  63. })
  64. if err != nil {
  65. t.Fatal(err)
  66. }
  67. }