Initial commit
This commit is contained in:
commit
3326d796f0
87 changed files with 15792 additions and 0 deletions
119
scripts/test-files/test_simple.go
Normal file
119
scripts/test-files/test_simple.go
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Mock labels for testing
|
||||
var testLabels = map[string]map[string]string{
|
||||
"redhat-bootc": {
|
||||
"com.redhat.bootc": "true",
|
||||
"ostree.bootable": "true",
|
||||
},
|
||||
"debian-bootc": {
|
||||
"com.debian.bootc": "true",
|
||||
"ostree.bootable": "true",
|
||||
},
|
||||
"both-labels": {
|
||||
"com.redhat.bootc": "true",
|
||||
"com.debian.bootc": "true",
|
||||
"ostree.bootable": "true",
|
||||
},
|
||||
"no-bootc": {
|
||||
"some.other.label": "value",
|
||||
},
|
||||
"no-ostree": {
|
||||
"com.debian.bootc": "true",
|
||||
},
|
||||
}
|
||||
|
||||
func isBootcImage(labels map[string]string) bool {
|
||||
// Check for Red Hat bootc label
|
||||
if val, exists := labels["com.redhat.bootc"]; exists && val == "true" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check for Debian bootc label
|
||||
if val, exists := labels["com.debian.bootc"]; exists && val == "true" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func validateBootcImage(labels map[string]string, imageRef string) error {
|
||||
if !isBootcImage(labels) {
|
||||
return fmt.Errorf("image %s is not a bootc image (missing com.redhat.bootc=true or com.debian.bootc=true label)", imageRef)
|
||||
}
|
||||
|
||||
// Check for required OSTree labels
|
||||
if val, exists := labels["ostree.bootable"]; !exists || val != "true" {
|
||||
return fmt.Errorf("image %s is not a bootc image (missing ostree.bootable=true label)", imageRef)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBootcType(labels map[string]string) string {
|
||||
if val, exists := labels["com.redhat.bootc"]; exists && val == "true" {
|
||||
return "redhat"
|
||||
}
|
||||
|
||||
if val, exists := labels["com.debian.bootc"]; exists && val == "true" {
|
||||
return "debian"
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Testing Debian bootc validation logic...")
|
||||
fmt.Println("")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
labels map[string]string
|
||||
expect bool
|
||||
}{
|
||||
{"Red Hat bootc", testLabels["redhat-bootc"], true},
|
||||
{"Debian bootc", testLabels["debian-bootc"], true},
|
||||
{"Both labels", testLabels["both-labels"], true},
|
||||
{"No bootc", testLabels["no-bootc"], false},
|
||||
{"No ostree", testLabels["no-ostree"], true}, // Should be true because it has bootc label
|
||||
}
|
||||
|
||||
passed := 0
|
||||
total := len(tests)
|
||||
|
||||
for _, test := range tests {
|
||||
fmt.Printf("Test: %s\n", test.name)
|
||||
fmt.Printf("Labels: %v\n", test.labels)
|
||||
|
||||
isBootc := isBootcImage(test.labels)
|
||||
bootcType := getBootcType(test.labels)
|
||||
err := validateBootcImage(test.labels, "test-image")
|
||||
|
||||
fmt.Printf("Is bootc: %t (expected: %t)\n", isBootc, test.expect)
|
||||
fmt.Printf("Bootc type: %s\n", bootcType)
|
||||
fmt.Printf("Validation error: %v\n", err)
|
||||
|
||||
if isBootc == test.expect {
|
||||
fmt.Printf("✅ PASS\n")
|
||||
passed++
|
||||
} else {
|
||||
fmt.Printf("❌ FAIL\n")
|
||||
}
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
fmt.Printf("Test Results: %d/%d passed\n", passed, total)
|
||||
|
||||
if passed == total {
|
||||
fmt.Println("🎉 All validation logic tests passed!")
|
||||
os.Exit(0)
|
||||
} else {
|
||||
fmt.Println("❌ Some validation logic tests failed")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
78
scripts/test-files/test_validation.go
Normal file
78
scripts/test-files/test_validation.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type ContainerInspect struct {
|
||||
Labels map[string]string `json:"Labels"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Println("Usage: go run test_validation.go <image-tag>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
imageTag := os.Args[1]
|
||||
|
||||
// Inspect the container image
|
||||
cmd := exec.Command("podman", "inspect", imageTag)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Printf("Error inspecting image %s: %v\n", imageTag, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parse the JSON output
|
||||
var containers []ContainerInspect
|
||||
if err := json.Unmarshal(output, &containers); err != nil {
|
||||
fmt.Printf("Error parsing JSON: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(containers) == 0 {
|
||||
fmt.Printf("No container information found for %s\n", imageTag)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
labels := containers[0].Labels
|
||||
fmt.Printf("Image: %s\n", imageTag)
|
||||
fmt.Printf("Labels: %v\n", labels)
|
||||
|
||||
// Test our validation logic
|
||||
isBootc := false
|
||||
bootcType := "unknown"
|
||||
|
||||
if val, exists := labels["com.redhat.bootc"]; exists && val == "true" {
|
||||
isBootc = true
|
||||
bootcType = "redhat"
|
||||
}
|
||||
|
||||
if val, exists := labels["com.debian.bootc"]; exists && val == "true" {
|
||||
isBootc = true
|
||||
bootcType = "debian"
|
||||
}
|
||||
|
||||
hasOstreeBootable := false
|
||||
if val, exists := labels["ostree.bootable"]; exists && val == "true" {
|
||||
hasOstreeBootable = true
|
||||
}
|
||||
|
||||
fmt.Printf("Is bootc image: %t\n", isBootc)
|
||||
fmt.Printf("Bootc type: %s\n", bootcType)
|
||||
fmt.Printf("Has ostree.bootable: %t\n", hasOstreeBootable)
|
||||
|
||||
if isBootc && hasOstreeBootable {
|
||||
fmt.Printf("✅ Image %s is a valid bootc image\n", imageTag)
|
||||
if bootcType == "debian" {
|
||||
fmt.Printf("✅ Image %s is specifically a Debian bootc image\n", imageTag)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("❌ Image %s is not a valid bootc image\n", imageTag)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue