Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Add tests for cloud object storate COS on IBM Cloud #61

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified tests/credentials.json.enc
Binary file not shown.
31 changes: 31 additions & 0 deletions tests/dat/cos/testcosread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var AWS = require('ibm-cos-sdk');
const endpoint = 's3-api.us-geo.objectstorage.softlayer.net';
const ibmAuthEndpoint = 'https://iam.ng.bluemix.net/oidc/token';
var params = {
Bucket: 'ibm-functions-devops-testing',
Key: 'testdata.txt'
}
var cos;
function main({
__bx_creds: {
"cloud-object-storage": { apikey },
"cloud-object-storage": { resource_instance_id }
}
}) {
cos = cos || new AWS.S3({
endpoint: endpoint,
ibmAuthEndpoint: ibmAuthEndpoint,
apiKeyId: apikey,
serviceInstanceId: resource_instance_id
});
return new Promise((resolve, reject) => {
cos.getObject(params, (err, data) => {
if (err) {
console.error("something bad happened", err);
reject({ Error: err })
} else {
resolve({ data: data.Body.toString('utf-8') })
}
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2017 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package integration

import common._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import java.io.File

import spray.json._
import org.scalatest.BeforeAndAfterAll
@RunWith(classOf[JUnitRunner])
class CredentialsIBMNodeJsCOSTests extends TestHelpers with WskTestHelpers with BeforeAndAfterAll {

implicit val wskprops: WskProps = WskProps()
var defaultKind = Some("nodejs-ibm:8")
val wsk = new Wsk
val datdir = System.getProperty("user.dir") + "/dat/"
val creds = TestUtils.getVCAPcredentials("cloud-object-storage")
val apikey = creds.get("apikey")
var resource_instance_id = creds.get("resource_instance_id")
val __bx_creds = JsObject(
"cloud-object-storage" -> JsObject(
"apikey" -> JsString(apikey),
"resource_instance_id" -> JsString(resource_instance_id)))

it should "Test connection to Cloud Object Storage COS on IBM Cloud" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val file = Some(new File(datdir, "cos/testcosread.js").toString())
assetHelper.withCleaner(wsk.action, "testCOS") { (action, _) =>
action.create(
"testCOS",
file,
main = Some("main"),
kind = defaultKind,
parameters = Map("__bx_creds" -> __bx_creds))
}
withActivation(wsk.activation, wsk.action.invoke("testCOS")) { activation =>
val response = activation.response
response.result.get.fields.get("error") shouldBe empty
response.result.get.fields.get("data") should be(
Some(JsString("This is a test file for IBM-Functions integration testing.")))
}
}
}