Fix loading and some tests
This commit is contained in:
parent
1ae06781d6
commit
432a3fdbc4
2
Makefile
2
Makefile
@ -16,7 +16,7 @@ clean:
|
|||||||
@rm -f ./api/v1alpha1/*.pb.go
|
@rm -f ./api/v1alpha1/*.pb.go
|
||||||
@rm -f kat-agent katcall
|
@rm -f kat-agent katcall
|
||||||
|
|
||||||
test:
|
test: generate
|
||||||
@echo "Running tests..."
|
@echo "Running tests..."
|
||||||
@go test ./...
|
@go test ./...
|
||||||
|
|
||||||
|
@ -3,12 +3,13 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
pb "git.dws.rip/dubey/kat/api/v1alpha1" // Adjust to your actual go module path
|
pb "git.dws.rip/dubey/kat/api/v1alpha1"
|
||||||
"gopkg.in/yaml.v3" // Add to go.mod: go get gopkg.in/yaml.v3
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = yaml.Unmarshal // Used for Quadlet parsing
|
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)
|
return nil, fmt.Errorf("cluster configuration file not found: %s", filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
yamlFile, err := ioutil.ReadFile(filePath)
|
yamlFile, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read cluster configuration file %s: %w", filePath, err)
|
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 {
|
if !ok {
|
||||||
return nil, fmt.Errorf("metadata section not found or invalid in %s", filePath)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to re-marshal metadata: %w", err)
|
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)
|
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 {
|
if !ok {
|
||||||
return nil, fmt.Errorf("spec section not found or invalid in %s", filePath)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to re-marshal spec: %w", err)
|
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)
|
return nil, fmt.Errorf("failed to unmarshal spec into proto: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,10 +31,10 @@ kind: ClusterConfiguration
|
|||||||
metadata:
|
metadata:
|
||||||
name: test-cluster
|
name: test-cluster
|
||||||
spec:
|
spec:
|
||||||
clusterCIDR: "10.0.0.0/16"
|
cluster_cidr: "10.0.0.0/16"
|
||||||
serviceCIDR: "10.1.0.0/16"
|
service_cidr: "10.1.0.0/16"
|
||||||
nodeSubnetBits: 8 # /24 for nodes
|
node_subnet_bits: 8 # /24 for nodes
|
||||||
apiPort: 8080 # Non-default
|
api_port: 8080 # Non-default
|
||||||
`
|
`
|
||||||
filePath := createTestClusterKatFile(t, yamlContent)
|
filePath := createTestClusterKatFile(t, yamlContent)
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ spec:
|
|||||||
clusterCIDR: "10.0.0.0/16"
|
clusterCIDR: "10.0.0.0/16"
|
||||||
serviceCIDR: "10.1.0.0/16"
|
serviceCIDR: "10.1.0.0/16"
|
||||||
`,
|
`,
|
||||||
wantErr: "metadata.name is required",
|
wantErr: "metadata section not found",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing clusterCIDR",
|
name: "missing clusterCIDR",
|
||||||
|
@ -129,7 +129,7 @@ func TestUntarQuadlets_FileTooLarge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUntarQuadlets_TotalSizeTooLarge(t *testing.T) {
|
func TestUntarQuadlets_TotalSizeTooLarge(t *testing.T) {
|
||||||
numFiles := (maxTotalQuadletSize / maxQuadletFileSize) + 2
|
numFiles := (maxTotalQuadletSize / maxQuadletFileSize) * 4
|
||||||
fileSize := maxQuadletFileSize / 2
|
fileSize := maxQuadletFileSize / 2
|
||||||
|
|
||||||
inputFiles := make(map[string]string)
|
inputFiles := make(map[string]string)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user