Skip to content
quarry Artifact [e2585146f6]
Login

Artifact [e2585146f6]

Artifact e2585146f6a1969e7ea1300d3945d1daa820b73c9f0d30c473175f40ee58b1a8:


package main

import (
	"os"
	"regexp"
	"strings"
	"testing"
)

// TestGoPinsAgree: go.mod is the one Go pin. deploy.sh reads it; the
// Dockerfile cannot read a file before FROM, so it carries a default
// that must say the same thing, or the image quietly builds with an
// older Go than every other path.
func TestGoPinsAgree(t *testing.T) {
	mod, err := os.ReadFile("../../go.mod")
	if err != nil {
		t.Fatal(err)
	}
	m := regexp.MustCompile(`(?m)^go (\S+)$`).FindSubmatch(mod)
	if m == nil {
		t.Fatal("go.mod has no go line")
	}
	want := string(m[1])
	df, err := os.ReadFile("../../Dockerfile")
	if err != nil {
		t.Fatal(err)
	}
	d := regexp.MustCompile(`(?m)^ARG GO_VERSION=(\S+)$`).FindSubmatch(df)
	if d == nil {
		t.Fatal("Dockerfile has no ARG GO_VERSION default")
	}
	if got := string(d[1]); got != want {
		t.Errorf("Dockerfile GO_VERSION=%s, go.mod says go %s", got, want)
	}
	if strings.Contains(string(df), "FROM golang:1.") {
		t.Error("Dockerfile names a golang image by number; use ${GO_VERSION}")
	}
}