Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
LeelaChacha authored and c-pius committed Jul 1, 2024
1 parent 9ed7e26 commit a5a9102
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/descriptor/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,28 @@ func TestGetDescriptor_OnEmptyCache_AddsDescriptorFromTemplate(t *testing.T) {
assert.NotNil(t, entry)
assert.Equal(t, expected.Name, entry.Name)
}

func TestSetDescriptor_OnEmptyTemplate_ReturnsErrTemplateNil(t *testing.T) {
descriptorProvider := provider.NewCachedDescriptorProvider(nil)

err := descriptorProvider.SetDescriptor(nil, nil)

require.Error(t, err)
require.ErrorIs(t, err, provider.ErrTemplateNil)
}

func TestSetDescriptor_OnProvidedDescriptor_ReturnsNoError(t *testing.T) {
descriptorProvider := provider.NewCachedDescriptorProvider(nil)
descriptorBefore := &v1beta2.Descriptor{
ComponentDescriptor: &compdesc.ComponentDescriptor{Metadata: compdesc.Metadata{ConfiguredVersion: "v1"}},
}
template := builder.NewModuleTemplateBuilder().WithDescriptor(descriptorBefore).Build()

descriptorAfter := &v1beta2.Descriptor{
ComponentDescriptor: &compdesc.ComponentDescriptor{Metadata: compdesc.Metadata{ConfiguredVersion: "v2"}},
}
err := descriptorProvider.SetDescriptor(template, descriptorAfter)

require.NoError(t, err)
assert.Equal(t, descriptorAfter, template.Spec.Descriptor.Object)
}

0 comments on commit a5a9102

Please sign in to comment.