Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/command.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/files.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/resource/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func (r *ResourceService) ApplyConfig(ctx context.Context, instanceID string) er
var instance *mpi.Instance
operator := r.instanceOperators[instanceID]

if operator == nil {
return fmt.Errorf("no instance operator found for instance %s", instanceID)
}

for _, resourceInstance := range r.resource.GetInstances() {
if resourceInstance.GetInstanceMeta().GetInstanceId() == instanceID {
instance = resourceInstance
Expand Down
14 changes: 12 additions & 2 deletions internal/resource/resource_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,29 +240,40 @@ func TestResourceService_ApplyConfig(t *testing.T) {
ctx := context.Background()

tests := []struct {
instanceID string
reloadErr error
validateErr error
expected error
name string
}{
{
name: "Test 1: Successful reload",
instanceID: protos.GetNginxOssInstance([]string{}).GetInstanceMeta().GetInstanceId(),
reloadErr: nil,
validateErr: nil,
expected: nil,
},
{
name: "Test 2: Failed reload",
instanceID: protos.GetNginxOssInstance([]string{}).GetInstanceMeta().GetInstanceId(),
reloadErr: fmt.Errorf("something went wrong"),
validateErr: nil,
expected: fmt.Errorf("failed to reload NGINX %w", fmt.Errorf("something went wrong")),
},
{
name: "Test 3: Failed validate",
instanceID: protos.GetNginxOssInstance([]string{}).GetInstanceMeta().GetInstanceId(),
reloadErr: nil,
validateErr: fmt.Errorf("something went wrong"),
expected: fmt.Errorf("failed validating config %w", fmt.Errorf("something went wrong")),
},
{
name: "Test 4: Unknown instance ID",
instanceID: "unknown",
reloadErr: nil,
validateErr: nil,
expected: fmt.Errorf("no instance operator found for instance unknown"),
},
}

for _, test := range tests {
Expand All @@ -283,8 +294,7 @@ func TestResourceService_ApplyConfig(t *testing.T) {
}
resourceService.resource.Instances = instances

reloadError := resourceService.ApplyConfig(ctx,
protos.GetNginxOssInstance([]string{}).GetInstanceMeta().GetInstanceId())
reloadError := resourceService.ApplyConfig(ctx, test.instanceID)
assert.Equal(t, test.expected, reloadError)
})
}
Expand Down