You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✨ Remove explicit type dependency from artefacts utils (#103)
<!--
Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors.
All rights reserved.
SPDX-License-Identifier: Proprietary
-->
### Description
This change removes explicit type dependency from artefacts utils
structs and functions by using generics instead of the explicit types
that were imported from "embedded-development-services-client".
The main issue was that the artefacts utils can only work with types
defined in "embedded-development-services-client", even if another
client package had the same type definitions, Go will still consider
these types as incompatible because they come from different packages.
My first approach was relying on interfaces and adaptor types that
converted specific client's types into types that implemented these
interfaces, but this meant that every user SDK will need this
boilerplate adaptor code to be able to work with the utils, which is
avoided using this approach.
Another limitation that I faced, is that Go does not allow type
manipulation in Generics (as in we can't take type T as an argument and
transform it into pointer type *T), which meant that I had to work with
either values only or pointer types, I chose to work with pointer types
only to allow for type inference in the user SDK of the utils.
This means that the only extra change that is still required to make
this work is to provide a static definition in the client generator for
"HalCollectionLinks":
```
// GetNextP returns the Next field pointer if set, nil otherwise.
func (o *HalCollectionLinks) GetNextP() *HalLinkData {
if o == nil || IsNil(o.Next) {
return nil
}
return o.Next
}
```
As you can also see in the "artefacts_test.go" file, the only change
that is required from the SDKs, is that if they need to instantiate
IArtefactManager, it will need explicit types to be passed to it
```
// Example instantiation
IArtefactManager[*client.ArtefactManagerItem, *client.HalLinkData]
```
<!--
Please put an `x` in the correct box e.g. `[x]` to indicate the testing
coverage of this change.
-->
- [x] This change is covered by existing or additional automated tests.
- [ ] Manual testing has been performed (and evidence provided) as
automated testing was not feasible.
- [ ] Additional tests are not required for this change (e.g.
documentation update).
---------
Co-authored-by: aorabdel <[email protected]>
err=fmt.Errorf("%w: returned artefact managers page[%T] is not of the expected type [%v]", commonerrors.ErrUnexpected, currentPage, "*ArtefactManagerCollection")
292
305
return
@@ -300,8 +313,8 @@ func (m *ArtefactManager) fetchJobArtefactsNextPage(ctx context.Context, current
300
313
err=fmt.Errorf("%w: returned page of artefact managers has no `next` link", commonerrors.ErrUnexpected)
// DownloadJobArtefactFromLink downloads a specific artefact into the output directory from a particular link. The artefact will be placed at the root of the output directory.
0 commit comments