From 432a3fdbc4d70708394f322fb43197e78f3734f6 Mon Sep 17 00:00:00 2001 From: Tanishq Dubey Date: Sat, 10 May 2025 18:54:10 -0400 Subject: [PATCH] Fix loading and some tests --- Makefile | 4 ++-- internal/config/parse.go | 17 +++++++++-------- internal/config/parse_test.go | 10 +++++----- internal/utils/tar_test.go | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 24cde5e..5c37ac3 100644 --- a/Makefile +++ b/Makefile @@ -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) \ No newline at end of file +# go get google.golang.org/grpc/cmd/protoc-gen-go-grpc (if you plan to use gRPC services soon) diff --git a/internal/config/parse.go b/internal/config/parse.go index b4bbff3..a32451b 100644 --- a/internal/config/parse.go +++ b/internal/config/parse.go @@ -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) } diff --git a/internal/config/parse_test.go b/internal/config/parse_test.go index bf133fd..1217d01 100644 --- a/internal/config/parse_test.go +++ b/internal/config/parse_test.go @@ -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", diff --git a/internal/utils/tar_test.go b/internal/utils/tar_test.go index c83563f..8444bb8 100644 --- a/internal/utils/tar_test.go +++ b/internal/utils/tar_test.go @@ -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)