@@ -69,16 +69,27 @@ func TestKubernetesModuleVersions(t *testing.T) {
6969 }
7070 },
7171 func (t * testing.T , pkgPath string , module * packages.Module ) bool {
72- modVer := module . Version
72+ expected := "v" + kubernetesVersion
7373 if module .Path != "k8s.io/kubernetes" {
7474 // All modules besides Kubernetes itself use v0 instead of v1.
75- modVer = strings .Replace (modVer , "v0." , "v1." , 1 )
75+ if suffix , found := strings .CutPrefix (expected , "v1." ); found {
76+ expected = "v0." + suffix
77+ }
7678 }
7779
78- return ! assert .Equal (t , "v" + kubernetesVersion , modVer ,
80+ ok := assert .Equal (t , expected , module . Version ,
7981 "Module version for package %s doesn't match: %+#v" ,
80- pkgPath , module ,
81- )
82+ pkgPath , module )
83+ if module .Replace == nil {
84+ return ok
85+ }
86+
87+ ok = assert .Nil (t , module .Replace .Replace ) && ok
88+ ok = assert .Equal (t , module .Path , module .Replace .Path ) && ok
89+ ok = assert .Equal (t , expected , module .Replace .Version ,
90+ "Replacing module version for package %s doesn't match: %+#v" ,
91+ pkgPath , module .Replace ) && ok
92+ return ok
8293 },
8394 )
8495}
@@ -94,9 +105,11 @@ func TestEtcdModuleVersions(t *testing.T) {
94105 strings .HasSuffix (modulePath , "/v" + etcdVersionParts [0 ])
95106 },
96107 func (t * testing.T , pkgPath string , module * packages.Module ) bool {
97- return ! assert .Equal (t , "v" + etcdVersion , module .Version ,
108+ ok := assert .Equal (t , "v" + etcdVersion , module .Version ,
98109 "Module version for package %s doesn't match: %+#v" ,
99110 )
111+ ok = assert .Nil (t , module .Replace ) && ok
112+ return ok
100113 },
101114 )
102115}
@@ -109,10 +122,11 @@ func TestContainerdModuleVersions(t *testing.T) {
109122 return modulePath == "github.com/containerd/containerd"
110123 },
111124 func (t * testing.T , pkgPath string , module * packages.Module ) bool {
112- return ! assert .Equal (t , "v" + containerdVersion , module .Version ,
125+ ok := assert .Equal (t , "v" + containerdVersion , module .Version ,
113126 "Module version for package %s doesn't match: %+#v" ,
114- pkgPath , module ,
115127 )
128+ ok = assert .Nil (t , module .Replace ) && ok
129+ return ok
116130 },
117131 )
118132}
@@ -125,10 +139,11 @@ func TestKonnectivityModuleVersions(t *testing.T) {
125139 return strings .HasPrefix (modulePath , "sigs.k8s.io/apiserver-network-proxy/" )
126140 },
127141 func (t * testing.T , pkgPath string , module * packages.Module ) bool {
128- return ! assert .Equal (t , "v" + konnectivityVersion , module .Version ,
142+ ok := assert .Equal (t , "v" + konnectivityVersion , module .Version ,
129143 "Module version for package %s doesn't match: %+#v" ,
130- pkgPath , module ,
131144 )
145+ ok = assert .Nil (t , module .Replace ) && ok
146+ return ok
132147 },
133148 )
134149}
@@ -161,15 +176,10 @@ func checkPackageModules(t *testing.T, filter func(modulePath string) bool, chec
161176
162177 packages .Visit (pkgs , func (p * packages.Package ) bool {
163178 if p .Module != nil && filter (p .Module .Path ) {
164- actual := p .Module
165- for actual .Replace != nil {
166- actual = actual .Replace
167- }
168-
169- if ! failedModules [actual .Path ] {
179+ if ! failedModules [p .Module .Path ] {
170180 numMatched ++
171- if ! check (t , p .PkgPath , actual ) {
172- failedModules [actual .Path ] = true
181+ if ! check (t , p .PkgPath , p . Module ) {
182+ failedModules [p . Module .Path ] = true
173183 }
174184 }
175185 }
0 commit comments