Skip to content

Commit 70a27c0

Browse files
committed
feat(tfsearch): TF-26847 TF-27256: Modified: added test cases
1 parent c7a3961 commit 70a27c0

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
import * as vscode from 'vscode';
7+
import { assert } from 'chai';
8+
import { activateExtension, getDocUri, open, testCompletion } from '../../helper';
9+
10+
suite('search (.tfquery.hcl)', () => {
11+
suite('root', function suite() {
12+
const docUri = getDocUri('main.tfquery.hcl');
13+
14+
this.beforeAll(async () => {
15+
await open(docUri);
16+
await activateExtension();
17+
});
18+
19+
this.afterAll(async () => {
20+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
21+
});
22+
23+
test('language is registered', async () => {
24+
const doc = await vscode.workspace.openTextDocument(docUri);
25+
assert.equal(doc.languageId, 'terraform-search', 'document language should be `terraform-search`');
26+
});
27+
28+
test('completes blocks available for search files', async () => {
29+
const expected = [
30+
new vscode.CompletionItem('list', vscode.CompletionItemKind.Class),
31+
new vscode.CompletionItem('locals', vscode.CompletionItemKind.Class),
32+
new vscode.CompletionItem('provider', vscode.CompletionItemKind.Class),
33+
new vscode.CompletionItem('variable', vscode.CompletionItemKind.Class),
34+
];
35+
36+
await testCompletion(docUri, new vscode.Position(1, 0), {
37+
items: expected,
38+
});
39+
});
40+
});
41+
42+
suite('list', function suite() {
43+
const docUri = getDocUri('main.tfquery.hcl');
44+
45+
this.beforeAll(async () => {
46+
await open(docUri);
47+
await activateExtension();
48+
});
49+
50+
this.afterAll(async () => {
51+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
52+
});
53+
54+
this.afterEach(async () => {
55+
// revert any changes made to the document after each test
56+
await vscode.commands.executeCommand('workbench.action.files.revert');
57+
});
58+
59+
test('language is registered', async () => {
60+
const doc = await vscode.workspace.openTextDocument(docUri);
61+
assert.equal(doc.languageId, 'terraform-search', 'document language should be `terraform-search`');
62+
});
63+
64+
test('completes attributes of list block - provider', async () => {
65+
const expected = [
66+
new vscode.CompletionItem('aws.this', vscode.CompletionItemKind.Variable),
67+
new vscode.CompletionItem('azurerm.this', vscode.CompletionItemKind.Variable),
68+
];
69+
70+
await testCompletion(docUri, new vscode.Position(24, 21), {
71+
items: expected,
72+
});
73+
});
74+
75+
test('completes attributes of list block - number variable', async () => {
76+
const expected = [
77+
new vscode.CompletionItem('count.index', vscode.CompletionItemKind.Variable),
78+
new vscode.CompletionItem('local.number_local', vscode.CompletionItemKind.Variable),
79+
new vscode.CompletionItem('var.number_variable', vscode.CompletionItemKind.Variable),
80+
];
81+
82+
await testCompletion(docUri, new vscode.Position(25, 21), {
83+
items: expected,
84+
});
85+
});
86+
87+
test('completes attributes of list block - boolean variable', async () => {
88+
const expected = [
89+
new vscode.CompletionItem('false', vscode.CompletionItemKind.EnumMember),
90+
new vscode.CompletionItem('true', vscode.CompletionItemKind.EnumMember),
91+
new vscode.CompletionItem('var.boolean_variable', vscode.CompletionItemKind.Variable),
92+
];
93+
94+
await testCompletion(docUri, new vscode.Position(26, 21), {
95+
items: expected,
96+
});
97+
});
98+
});
99+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.0"
6+
}
7+
azurerm = {
8+
source = "hashicorp/azurerm"
9+
version = "=3.0.0"
10+
}
11+
}
12+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
provider "aws" {
3+
alias = "this"
4+
}
5+
6+
provider "azurerm" {
7+
alias = "this"
8+
}
9+
10+
variable "boolean_variable" {
11+
default = true
12+
type = bool
13+
}
14+
15+
locals {
16+
number_local = 500
17+
}
18+
19+
variable "number_variable" {
20+
default = 10
21+
type = number
22+
}
23+
24+
list "concept_pet" "name_1" {
25+
provider =
26+
limit =
27+
include_resource =
28+
count = 10
29+
config {
30+
31+
}
32+
}

0 commit comments

Comments
 (0)