Skip to content

Commit

Permalink
Stack Creat/Select/Upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBoyle committed Sep 18, 2020
1 parent c33bcda commit aaced4f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
22 changes: 17 additions & 5 deletions sdk/nodejs/tests/automation/localWorkspace.spec.ts
Expand Up @@ -13,16 +13,15 @@
// limitations under the License.

import * as assert from "assert";
import * as upath from "upath";

import { LocalWorkspace } from "../../x/automation/localWorkspace";
import { ProjectSettings } from "../../x/automation/projectSettings";

import * as upath from "upath";
import { fileURLToPath } from "url";
import { Stack } from "../../x/automation/stack";
import { asyncTest } from "../util";


describe("LocalWorkspace", () => {

it(`projectSettings from yaml/yml/json`, asyncTest(async () => {
for (const ext of ["yaml", "yml", "json"]) {
const ws = new LocalWorkspace({ workDir: upath.joinSafe(__dirname, "data", ext) });
Expand All @@ -44,7 +43,7 @@ describe("LocalWorkspace", () => {
}
}));

it(`create/select/remove stack`, asyncTest(async () => {
it(`create/select/remove LocalWorkspace stack`, asyncTest(async () => {
const projectSettings = new ProjectSettings();
projectSettings.name = "node_test";
projectSettings.runtime.name = "nodejs";
Expand All @@ -55,6 +54,19 @@ describe("LocalWorkspace", () => {
await ws.selectStack(stackName);
await ws.removeStack(stackName);
}));

it(`Create/Select/Upsert Stack`, asyncTest(async () => {
const projectSettings = new ProjectSettings();
projectSettings.name = "node_test";
projectSettings.runtime.name = "nodejs";
const ws = new LocalWorkspace({ projectSettings });
await ws.ready;
const stackName = `int_test${getTestSuffix()}`;
await Stack.Create(stackName, ws);
await Stack.Select(stackName, ws);
await Stack.Upsert(stackName, ws);
await ws.removeStack(stackName);
}));
});

const getTestSuffix = () => {
Expand Down
49 changes: 48 additions & 1 deletion sdk/nodejs/x/automation/stack.ts
Expand Up @@ -12,4 +12,51 @@
// See the License for the specific language governing permissions and
// limitations under the License.

export class Stack {}
import { Workspace } from "./workspace";

export type StackInitMode = "create" | "select" | "upsert";

export class Stack {
ready: Promise<any>;
private name: string;
private workspace: Workspace;
public static async Create(name: string, workspace: Workspace): Promise<Stack> {
const stack = new Stack(name, workspace, "create");
await stack.ready;
return Promise.resolve(stack);
}
public static async Select(name: string, workspace: Workspace): Promise<Stack> {
const stack = new Stack(name, workspace, "select");
await stack.ready;
return Promise.resolve(stack);
}
public static async Upsert(name: string, workspace: Workspace): Promise<Stack> {
const stack = new Stack(name, workspace, "upsert");
await stack.ready;
return Promise.resolve(stack);
}
constructor(name: string, workspace: Workspace, mode: StackInitMode) {
this.name = name;
this.workspace = workspace;

switch (mode) {
case "create":
this.ready = workspace.createStack(name);
return this;
case "select":
this.ready = workspace.selectStack(name);
return this;
case "upsert":
this.ready = workspace.createStack(name).catch(()=> {
return workspace.selectStack(name);
});
return this;
default:
throw new Error(`unexpected Stack creation mode: ${mode}`);
}
}
}

export function FullyQualifiedStackName(org: string, project: string, stack: string): string {
return `${org}/${project}/${stack}`;
}

0 comments on commit aaced4f

Please sign in to comment.