Skip to content

Commit

Permalink
passing get occurrence test
Browse files Browse the repository at this point in the history
  • Loading branch information
murog committed May 14, 2019
1 parent 397455b commit 4cdd1ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
5 changes: 2 additions & 3 deletions container-analysis/snippets/createOccurrence.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ const createOccurence = async(
}
}
});

console.log(`Occurrence created for image ${occurrence.resource.uri}.`);

console.log(`Occurrence created ${occurrence.name}.`);
return occurrence;
};
// [END containeranalysis_create_occurrence]

Expand Down
14 changes: 13 additions & 1 deletion container-analysis/snippets/getOccurrence.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
// [START containeranalysis_get_occurrence]
// Retrieves and prints a specified Occurrence from the server
const getOccurrence = async(

projectId = 'your-project-id', // Your GCP Project ID
occurrenceId = 'my-occurrence', // Your Occurrence name
) => {
// Import the library and create a client
const grafeas = require('@google-cloud/grafeas');
const client = new grafeas.v1.GrafeasClient();

// Get full path to occurrence
const formattedName = client.occurrencePath(projectId, occurrenceId)

// Get occurrence
const [occurrence] = await client.getOccurrence({
name: formattedName
});

console.log(`Occurrence name: ${occurrence.name}`)

};
// [END containeranalysis_get_occurrence]

Expand Down
31 changes: 22 additions & 9 deletions container-analysis/snippets/system-test/containerAnalysis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const execSync = cmd => cp.execSync(cmd, { encoding: 'utf-8' });
const projectId = process.env.GCLOUD_PROJECT;
const noteId = `test-note-${uuid.v4()}`;
const formattedNoteName = `projects/${projectId}/notes/${noteId}`
const formattedOccName = `projects/${projectId}/occurences`
const resourceUrl = `gcr.io/project/image`;


Expand All @@ -33,7 +32,27 @@ describe('Note tests', async function () {
const output = execSync(`node createOccurrence.js "${projectId}" "${noteId}" "${projectId}" "${resourceUrl}"`);
assert.match(
output,
new RegExp(`Occurrence created for image ${resourceUrl}.`)
new RegExp(`Occurrence created`)
)

});

it('should get occurrence', async function() {
const grafeas = require('@google-cloud/grafeas');
const client = new grafeas.v1.GrafeasClient();
const formattedParent = client.projectPath(projectId);
const [occurrences] = await client.listOccurrences({
parent: formattedParent
});
assert(occurrences.length > 0);

const occurrence = occurrences[0];
const occurrenceId = occurrence.name.split("/")[3];

const output = execSync(`node getOccurrence.js "${projectId}" "${occurrenceId}"`);
assert.match(
output,
new RegExp(`Occurrence name: ${occurrence.name}`)
)
});

Expand All @@ -56,13 +75,7 @@ describe('Note tests', async function () {
// )
// });
// // TODO: finalize inputs
// it('should get occurrence', async function() {
// const output = execSync(`node getOccurrence.js`);
// assert.match(
// output,
// new RegExp(`Occurrence name: `)
// )
// });

// // TODO:
// it('should delete occurrence', async function() {
// const output = execSync(`node deleteOccurrence.js`);
Expand Down

0 comments on commit 4cdd1ef

Please sign in to comment.