version_test.go 800 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) 2022 Tailscale Inc & 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. package tailscaleroot
  5. import (
  6. "fmt"
  7. "os"
  8. "regexp"
  9. "strings"
  10. "testing"
  11. )
  12. func TestDockerfileVersion(t *testing.T) {
  13. goMod, err := os.ReadFile("go.mod")
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. m := regexp.MustCompile(`(?m)^go (\d\.\d+)\r?$`).FindStringSubmatch(string(goMod))
  18. if m == nil {
  19. t.Fatalf("didn't find go version in go.mod")
  20. }
  21. goVersion := m[1]
  22. dockerFile, err := os.ReadFile("Dockerfile")
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. wantSub := fmt.Sprintf("FROM golang:%s-alpine AS build-env", goVersion)
  27. if !strings.Contains(string(dockerFile), wantSub) {
  28. t.Errorf("didn't find %q in Dockerfile", wantSub)
  29. }
  30. }