-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2becc8
commit a8aba36
Showing
5 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package npmblob_test | ||
|
||
import ( | ||
. "github.com/mandelsoft/goutils/testutils" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
. "ocm.software/ocm/api/helper/builder" | ||
ocmutils "ocm.software/ocm/api/ocm/ocmutils" | ||
"ocm.software/ocm/api/tech/npm/npmtest" | ||
|
||
"ocm.software/ocm/api/ocm/elements" | ||
me "ocm.software/ocm/api/ocm/elements/artifactblob/npmblob" | ||
resourcetypes "ocm.software/ocm/api/ocm/extensions/artifacttypes" | ||
"ocm.software/ocm/api/ocm/extensions/repositories/composition" | ||
) | ||
|
||
var _ = Describe("blobaccess for npm", func() { | ||
Context("npm filesystem repository", func() { | ||
var env *Builder | ||
|
||
BeforeEach(func() { | ||
env = NewBuilder(npmtest.TestData()) | ||
}) | ||
|
||
AfterEach(func() { | ||
MustBeSuccessful(env.Cleanup()) | ||
}) | ||
|
||
It("blobaccess for package", func() { | ||
cv := composition.NewComponentVersion(env.OCMContext(), "acme.org/test", "1.0.0") | ||
defer Close(cv) | ||
|
||
a := me.ResourceAccess(env.OCMContext(), Must(elements.ResourceMeta("blob", resourcetypes.OCM_JSON, elements.WithLocalRelation())), "file://"+npmtest.NPMPATH, npmtest.PACKAGE, npmtest.VERSION, me.WithCachingFileSystem(env.FileSystem())) | ||
Expect(a.ReferenceHint()).To(Equal(npmtest.PACKAGE + ":" + npmtest.VERSION)) | ||
|
||
Expect(len(Must(ocmutils.GetResourceData(a)))).To(Equal(npmtest.ARTIFACT_SIZE)) | ||
}) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package npmblob | ||
|
||
import ( | ||
"github.com/mandelsoft/goutils/optionutils" | ||
"github.com/mandelsoft/logging" | ||
"github.com/mandelsoft/vfs/pkg/vfs" | ||
|
||
"ocm.software/ocm/api/credentials" | ||
"ocm.software/ocm/api/datacontext" | ||
"ocm.software/ocm/api/ocm/cpi" | ||
"ocm.software/ocm/api/ocm/elements/artifactblob/api" | ||
"ocm.software/ocm/api/tech/maven" | ||
base "ocm.software/ocm/api/utils/blobaccess/npm" | ||
) | ||
|
||
type Option = optionutils.Option[*Options] | ||
|
||
type Options struct { | ||
api.Options | ||
Blob base.Options | ||
} | ||
|
||
var ( | ||
_ api.GeneralOptionsProvider = (*Options)(nil) | ||
_ Option = (*Options)(nil) | ||
) | ||
|
||
func (o *Options) ApplyTo(opts *Options) { | ||
o.Options.ApplyTo(&opts.Options) | ||
o.Blob.ApplyTo(&opts.Blob) | ||
} | ||
|
||
func (o *Options) Apply(opts ...Option) { | ||
optionutils.ApplyOptions(o, opts...) | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// General Options | ||
|
||
func WithHint(h string) Option { | ||
return api.WrapHint[Options](h) | ||
} | ||
|
||
func WithHintForCoords(coords *maven.Coordinates) Option { | ||
if coords.IsPackage() { | ||
return WithHint(coords.GAV()) | ||
} | ||
return optionutils.NoOption[*Options]{} | ||
} | ||
|
||
func WithGlobalAccess(a cpi.AccessSpec) Option { | ||
return api.WrapGlobalAccess[Options](a) | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Local Options | ||
|
||
func mapBaseOption(opts *Options) *base.Options { | ||
return &opts.Blob | ||
} | ||
|
||
func wrapBase(o base.Option) Option { | ||
return optionutils.OptionWrapperFunc[*base.Options, *Options](o, mapBaseOption) | ||
} | ||
|
||
func WithCredentialContext(credctx credentials.ContextProvider) Option { | ||
return wrapBase(base.WithCredentialContext(credctx)) | ||
} | ||
|
||
func WithLoggingContext(logctx logging.ContextProvider) Option { | ||
return wrapBase(base.WithLoggingContext(logctx)) | ||
} | ||
|
||
func WithCachingContext(cachectx datacontext.Context) Option { | ||
return wrapBase(base.WithCachingContext(cachectx)) | ||
} | ||
|
||
func WithCachingFileSystem(fs vfs.FileSystem) Option { | ||
return wrapBase(base.WithCachingFileSystem(fs)) | ||
} | ||
|
||
func WithCachingPath(p string) Option { | ||
return wrapBase(base.WithCachingPath(p)) | ||
} | ||
|
||
func WithCredentials(c credentials.Credentials) Option { | ||
return wrapBase(base.WithCredentials(c)) | ||
} | ||
|
||
func WithPathFileSystem(fs vfs.FileSystem) Option { | ||
return wrapBase(base.WithPathFileSystem(fs)) | ||
} | ||
|
||
func WithDataContext(ctx datacontext.Context) Option { | ||
return wrapBase(base.WithDataContext(ctx)) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package npmblob | ||
|
||
import ( | ||
"github.com/mandelsoft/goutils/generics" | ||
"github.com/mandelsoft/goutils/optionutils" | ||
|
||
"ocm.software/ocm/api/ocm" | ||
"ocm.software/ocm/api/ocm/compdesc" | ||
"ocm.software/ocm/api/ocm/cpi" | ||
resourcetypes "ocm.software/ocm/api/ocm/extensions/artifacttypes" | ||
base "ocm.software/ocm/api/utils/blobaccess/npm" | ||
common "ocm.software/ocm/api/utils/misc" | ||
) | ||
|
||
const TYPE = resourcetypes.NPM_PACKAGE | ||
|
||
func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, repo, pkg, version string, opts ...Option) cpi.ArtifactAccess[M] { | ||
eff := optionutils.EvalOptions(optionutils.WithDefaults(opts, WithHint(common.NewNameVersion(pkg, version).String()), WithCredentialContext(ctx))...) | ||
|
||
if meta.GetType() == "" { | ||
meta.SetType(TYPE) | ||
} | ||
|
||
blobprov := base.Provider(repo, pkg, version, &eff.Blob) | ||
accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, eff.Hint, eff.Global) | ||
// strange type cast is required by Go compiler, meta has the correct type. | ||
return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) | ||
} | ||
|
||
func ResourceAccess(ctx ocm.Context, meta *ocm.ResourceMeta, repo, pkg, version string, opts ...Option) cpi.ResourceAccess { | ||
return Access(ctx, meta, repo, pkg, version, opts...) | ||
} | ||
|
||
func SourceAccess(ctx ocm.Context, meta *ocm.SourceMeta, repo, pkg, version string, opts ...Option) cpi.SourceAccess { | ||
return Access(ctx, meta, repo, pkg, version, opts...) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package npmblob_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "NPM Blob Access Test Suite") | ||
} |
This file contains 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