Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 74 additions & 25 deletions fulfillment-service/internal/rendering/table_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,33 +150,33 @@ var _ = Describe("Table renderer", func() {
})
})

Describe("Integer columns", func() {
renderInstanceTypes := func(ctx context.Context, items []*publicv1.InstanceType) string {
objectHelper := makeObjectHelper(&publicv1.InstanceType{})
lookupHelper := makeLookupHelper()
renderInstanceTypes := func(ctx context.Context, items []*publicv1.InstanceType) string {
objectHelper := makeObjectHelper(&publicv1.InstanceType{})
lookupHelper := makeLookupHelper()

helper := reflection.NewMockHelper(ctrl)
helper.EXPECT().
Lookup(objectHelper.String()).
Return(objectHelper).
AnyTimes()
helper.EXPECT().
Lookup(gomock.Any()).
Return(lookupHelper).
AnyTimes()
helper := reflection.NewMockHelper(ctrl)
helper.EXPECT().
Lookup(objectHelper.String()).
Return(objectHelper).
AnyTimes()
helper.EXPECT().
Lookup(gomock.Any()).
Return(lookupHelper).
AnyTimes()

buffer := &bytes.Buffer{}
renderer, err := NewTableRenderer().
SetLogger(logger).
SetHelper(helper).
SetWriter(buffer).
Build()
Expect(err).ToNot(HaveOccurred())
err = renderer.Render(ctx, items)
Expect(err).ToNot(HaveOccurred())
return buffer.String()
}
buffer := &bytes.Buffer{}
renderer, err := NewTableRenderer().
SetLogger(logger).
SetHelper(helper).
SetWriter(buffer).
Build()
Expect(err).ToNot(HaveOccurred())
err = renderer.Render(ctx, items)
Expect(err).ToNot(HaveOccurred())
return buffer.String()
}

Describe("Integer columns", func() {
It("Renders integer fields as plain numbers", func(ctx context.Context) {
output := renderInstanceTypes(
ctx,
Expand All @@ -194,11 +194,60 @@ var _ = Describe("Table renderer", func() {
}.Build(),
},
)
Expect(output).To(MatchRegexp(`4\s+16\s+ACTIVE`))
Expect(output).To(MatchRegexp(`4\s+16\s+.*ACTIVE`))
Expect(output).ToNot(ContainSubstring("%!s"))
})
})

Describe("Optional GPU columns", func() {
It("Renders GPU fields for GPU-enabled InstanceType", func(ctx context.Context) {
output := renderInstanceTypes(
ctx,
[]*publicv1.InstanceType{
publicv1.InstanceType_builder{
Id: "gpu-a100-8core",
Metadata: publicv1.Metadata_builder{
Name: "gpu-a100-8core",
}.Build(),
Spec: publicv1.InstanceTypeSpec_builder{
Cores: 8,
MemoryGib: 64,
State: publicv1.InstanceTypeState_INSTANCE_TYPE_STATE_ACTIVE,
Gpu: publicv1.GpuSpec_builder{
PciDeviceSelector: "10DE:20B0",
ResourceName: "nvidia.com/A100",
Count: 1,
}.Build(),
}.Build(),
}.Build(),
},
)
Expect(output).To(ContainSubstring("nvidia.com/A100"))
Expect(output).To(MatchRegexp(`1\s+nvidia\.com/A100\s+ACTIVE`))
})

It("Renders blank GPU columns for non-GPU InstanceType", func(ctx context.Context) {
output := renderInstanceTypes(
ctx,
[]*publicv1.InstanceType{
publicv1.InstanceType_builder{
Id: "standard-4-16",
Metadata: publicv1.Metadata_builder{
Name: "standard-4-16",
}.Build(),
Spec: publicv1.InstanceTypeSpec_builder{
Cores: 4,
MemoryGib: 16,
State: publicv1.InstanceTypeState_INSTANCE_TYPE_STATE_ACTIVE,
}.Build(),
}.Build(),
},
)
Expect(output).To(ContainSubstring("GPU NAME"))
Expect(output).To(MatchRegexp(`16\s+0\s+-\s+ACTIVE`))
})
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.

It("Compiles CEL expressions successfully for all table definitions", func(ctx context.Context) {
// Collect all table definition files:
tableFiles, err := filepath.Glob("tables/*.yaml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ columns:
- header: MEMORY
value: this.spec.memory_gib

- header: GPUS
value: "has(this.spec.gpu) ? this.spec.gpu.count : 0"

- header: GPU NAME
value: "has(this.spec.gpu) ? this.spec.gpu.resource_name : '-'"

- header: STATE
value: this.spec.state
type: osac.private.v1.InstanceTypeState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ columns:
- header: MEMORY
value: this.spec.memory_gib

- header: GPUS
value: "has(this.spec.gpu) ? this.spec.gpu.count : 0"

- header: GPU NAME
value: "has(this.spec.gpu) ? this.spec.gpu.resource_name : '-'"

- header: STATE
value: this.spec.state
type: osac.public.v1.InstanceTypeState
Expand Down
Loading