deb-bootc-image-builder/bib/internal/debian-patch/test_validation.go
robojerk be2b81ca6d
Some checks failed
Tests / test (1.21.x) (push) Failing after 1s
Tests / test (1.22.x) (push) Failing after 1s
Update Go code to remove Red Hat dependencies and use Debian equivalents
2025-08-11 09:39:18 -07:00

78 lines
1.8 KiB
Go

package debianpatch
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)
}
}