Fix/import template fix: use sentinel error for resource not-found detection in import#202
Merged
Merged
Conversation
eeed58e to
b6cb7c5
Compare
…tures Also fixes import group --replace failing when the group does not yet exist on the server (same root cause as the template fix). Adds the testdata fixture files that were gitignored and missing from the branch, causing the test binary to panic on init.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes ipctl import template --replace failing with "item with name '...' not found" when the template does not yet exist on the server. The root cause was fragile err.Error() string comparisons in runners that checked for resource-specific strings (e.g. "template not found"), while FindByName returned a generic "item with name '...' not found" string — the two never matched.
Type of Change
Changes Made
Changes
pkg/resources/base.go — Added ErrNotFound sentinel and NotFoundError struct with an Is() method so errors.Is(err, ErrNotFound) works correctly
pkg/resources/FindByName — Added kind parameter so errors report the resource type (e.g. "template 'foo' not found")
pkg/resources/{accounts,device_groups,groups,jsonforms,models,projects,templates,workflows}.go — Updated all FindByName call sites to pass the resource kind
internal/runners/{templates,models,jsonforms}.go — Replaced err.Error() != "X not found" string checks with !errors.Is(err, resources.ErrNotFound)
pkg/resources/base_test.go — Unit tests for FindByName and ErrNotFound
internal/runners/templates_test.go — Integration tests covering the fixed import scenario
Testing
done
Unit tests (pkg/resources/base_test.go)
done
Integration tests (internal/runners/templates_test.go)
done
Full test suite passes (make test)
done
Manually verified import template
Related Issues
Closes #196
Checklist
make setupor relevant profiletype: subject)enhancement,bug,documentation,refactor,chore)