generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test to enforce that we always have builtin schemas for linked k8…
…s version
- Loading branch information
1 parent
e5fa5ce
commit fac15fd
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package openapiclient_test | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/util/version" | ||
"sigs.k8s.io/kubectl-validate/pkg/openapiclient" | ||
) | ||
|
||
var LinkedK8sVersion *version.Version = func() *version.Version { | ||
cmd := exec.Command("go", "list", "-m", "-mod=mod", "-f", "{{if eq .Path \"k8s.io/api\"}}{{.Version}}{{end}}", "all") | ||
cmd.Dir = "" | ||
out, err := cmd.Output() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return version.MustParseSemantic(strings.TrimSpace(string(out))) | ||
}() | ||
|
||
func TestHasUptoDateBuiltinSchemas(t *testing.T) { | ||
t.Log(LinkedK8sVersion) | ||
|
||
if LinkedK8sVersion.Major() != 0 { | ||
t.Fatalf("Major version of linked k8s.io/api is not 0: %v", LinkedK8sVersion) | ||
} | ||
|
||
for i := 23; i <= int(LinkedK8sVersion.Minor()); i++ { | ||
found := false | ||
for _, version := range openapiclient.HardcodedBuiltinVersions { | ||
if version == "1."+fmt.Sprint(i) { | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found { | ||
t.Errorf("Missing builtin version v1.%d", i) | ||
} | ||
} | ||
} |