Fix loading and some tests

This commit is contained in:
Tanishq Dubey 2025-05-10 18:54:10 -04:00
parent 1ae06781d6
commit 432a3fdbc4
No known key found for this signature in database
GPG Key ID: CFC1931B84DFC3F9
4 changed files with 17 additions and 16 deletions

View File

@ -16,7 +16,7 @@ clean:
@rm -f ./api/v1alpha1/*.pb.go
@rm -f kat-agent katcall
test:
test: generate
@echo "Running tests..."
@go test ./...
@ -30,4 +30,4 @@ lint:
# Add to go.mod if not already present by go install
# go get google.golang.org/protobuf/cmd/protoc-gen-go
# go get google.golang.org/grpc/cmd/protoc-gen-go-grpc (if you plan to use gRPC services soon)
# go get google.golang.org/grpc/cmd/protoc-gen-go-grpc (if you plan to use gRPC services soon)

View File

@ -3,12 +3,13 @@ package config
import (
"fmt"
"io/ioutil"
"net"
"os"
pb "git.dws.rip/dubey/kat/api/v1alpha1" // Adjust to your actual go module path
"gopkg.in/yaml.v3" // Add to go.mod: go get gopkg.in/yaml.v3
pb "git.dws.rip/dubey/kat/api/v1alpha1"
"gopkg.in/yaml.v3"
"encoding/json"
)
var _ = yaml.Unmarshal // Used for Quadlet parsing
@ -19,7 +20,7 @@ func ParseClusterConfiguration(filePath string) (*pb.ClusterConfiguration, error
return nil, fmt.Errorf("cluster configuration file not found: %s", filePath)
}
yamlFile, err := ioutil.ReadFile(filePath)
yamlFile, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("failed to read cluster configuration file %s: %w", filePath, err)
}
@ -43,11 +44,11 @@ func ParseClusterConfiguration(filePath string) (*pb.ClusterConfiguration, error
if !ok {
return nil, fmt.Errorf("metadata section not found or invalid in %s", filePath)
}
metadataBytes, err := yaml.Marshal(metadataMap)
metadataBytes, err := json.Marshal(metadataMap)
if err != nil {
return nil, fmt.Errorf("failed to re-marshal metadata: %w", err)
}
if err = yaml.Unmarshal(metadataBytes, &config.Metadata); err != nil {
if err = json.Unmarshal(metadataBytes, &config.Metadata); err != nil {
return nil, fmt.Errorf("failed to unmarshal metadata into proto: %w", err)
}
@ -55,11 +56,11 @@ func ParseClusterConfiguration(filePath string) (*pb.ClusterConfiguration, error
if !ok {
return nil, fmt.Errorf("spec section not found or invalid in %s", filePath)
}
specBytes, err := yaml.Marshal(specMap)
specBytes, err := json.Marshal(specMap)
if err != nil {
return nil, fmt.Errorf("failed to re-marshal spec: %w", err)
}
if err = yaml.Unmarshal(specBytes, &config.Spec); err != nil {
if err = json.Unmarshal(specBytes, &config.Spec); err != nil {
return nil, fmt.Errorf("failed to unmarshal spec into proto: %w", err)
}

View File

@ -31,10 +31,10 @@ kind: ClusterConfiguration
metadata:
name: test-cluster
spec:
clusterCIDR: "10.0.0.0/16"
serviceCIDR: "10.1.0.0/16"
nodeSubnetBits: 8 # /24 for nodes
apiPort: 8080 # Non-default
cluster_cidr: "10.0.0.0/16"
service_cidr: "10.1.0.0/16"
node_subnet_bits: 8 # /24 for nodes
api_port: 8080 # Non-default
`
filePath := createTestClusterKatFile(t, yamlContent)
@ -97,7 +97,7 @@ spec:
clusterCIDR: "10.0.0.0/16"
serviceCIDR: "10.1.0.0/16"
`,
wantErr: "metadata.name is required",
wantErr: "metadata section not found",
},
{
name: "missing clusterCIDR",

View File

@ -129,7 +129,7 @@ func TestUntarQuadlets_FileTooLarge(t *testing.T) {
}
func TestUntarQuadlets_TotalSizeTooLarge(t *testing.T) {
numFiles := (maxTotalQuadletSize / maxQuadletFileSize) + 2
numFiles := (maxTotalQuadletSize / maxQuadletFileSize) * 4
fileSize := maxQuadletFileSize / 2
inputFiles := make(map[string]string)