Skip to content

Commit

Permalink
INT - match to spec resources by name
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway committed Mar 11, 2024
1 parent e958fa5 commit c493590
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
15 changes: 13 additions & 2 deletions discovery/pkg/apigee/pollproxiesjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type proxyClient interface {

type proxyCache interface {
GetSpecWithPath(path string) (*specCacheItem, error)
GetSpecWithName(name string) (*specCacheItem, error)
GetSpecPathWithEndpoint(endpoint string) (string, error)
AddPublishedServiceToCache(cacheKey string, serviceBody *apic.ServiceBody)
}
Expand Down Expand Up @@ -278,13 +279,23 @@ func (j *pollProxiesJob) specFromRevision(ctx context.Context) string {
logger := getLoggerFromContext(ctx)
logger.Trace("checking revision resource files")

// get the spec using the association.json file, if it exists
revision := ctx.Value(revNameField).(*models.ApiProxyRevision)
for _, resource := range revision.ResourceFiles.ResourceFile {
if resource.Type == openapi && resource.Name == association {
return j.getSpecFromResourceFile(ctx, resource.Type, resource.Name)
if resource.Type != openapi || resource.Name != association {
continue
}
if path := j.getSpecFromResourceFile(ctx, resource.Type, resource.Name); path != "" {
return path
}
}

// get a spec match based off the proxy name to the spec name
specData, _ := j.cache.GetSpecWithName(revision.Name)
if specData != nil {
return specData.ContentPath
}

return j.getSpecFromVirtualHosts(ctx)
}

Expand Down
31 changes: 28 additions & 3 deletions discovery/pkg/apigee/pollproxiesjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
func Test_pollProxiesJob(t *testing.T) {
tests := []struct {
name string
specPath bool
specName bool
allProxyErr bool
getDeploymentErr bool
getRevisionErr bool
Expand All @@ -38,11 +40,19 @@ func Test_pollProxiesJob(t *testing.T) {
}{
{
name: "should create proxy when spec in revision resource file",
specPath: true,
specFound: true,
specInResource: true,
hasOauth: true,
hasAPIKey: true,
},
{
name: "should create proxy when spec is matched by name",
specName: true,
specFound: true,
hasOauth: true,
hasAPIKey: true,
},
{
name: "should create proxy when spec url on revision",
specFound: true,
Expand Down Expand Up @@ -91,7 +101,7 @@ func Test_pollProxiesJob(t *testing.T) {
hasAPIKey: tc.hasAPIKey,
hasOauth: tc.hasOauth,
}
proxyJob := newPollProxiesJob(client, mockProxyCache{}, func() bool { return true }, 10)
proxyJob := newPollProxiesJob(client, mockProxyCache{pathSpec: tc.specPath, nameSpec: tc.specName}, func() bool { return true }, 10)
assert.False(t, proxyJob.FirstRunComplete())

// receive the publish call and validate what was published
Expand Down Expand Up @@ -260,10 +270,25 @@ func (m mockProxyClient) GetRevisionPolicyByName(apiName, revision, policyName s

func (m mockProxyClient) IsReady() bool { return false }

type mockProxyCache struct{}
type mockProxyCache struct {
pathSpec bool
nameSpec bool
}

func (m mockProxyCache) GetSpecWithPath(path string) (*specCacheItem, error) {
return &specCacheItem{}, nil
if m.pathSpec {
return &specCacheItem{}, nil
} else {
return nil, nil
}
}

func (m mockProxyCache) GetSpecWithName(path string) (*specCacheItem, error) {
if m.nameSpec {
return &specCacheItem{}, nil
} else {
return nil, nil
}
}

func (m mockProxyCache) GetSpecPathWithEndpoint(endpoint string) (string, error) {
Expand Down

0 comments on commit c493590

Please sign in to comment.