-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi proto file support #3006
Merged
develohpanda
merged 24 commits into
develop
from
feature/ins-385-import-proto-file-directory
Jan 25, 2021
Merged
Multi proto file support #3006
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
64bf25b
feat: add db model and updated selector
develohpanda 58b3828
feat: read root dir and store all proto files
develohpanda 90935fe
feat: recursively read proto directory and store in db
develohpanda bc3c2ac
feat: add nesting to list
develohpanda 2e20459
feat: spacing and layout improvements, disable editing when item is n…
develohpanda d75a2eb
fix: add key to component
develohpanda 019523e
feat: add stories for indented and selectable list items
develohpanda 0978634
feat: delete empty folders, show alert when nothing is imported, allo…
develohpanda ecc2181
feat: write file using the id and modified time instead of math.random
develohpanda c625a04
chore: comments and small refactor
develohpanda 6f6e6cd
feat: recursively write and consume a cached proto directory! woooo
develohpanda 934fa16
fix: proto-loader includeDirs must include every dir, not only the root
develohpanda 93e39dd
chore: extract logic from modal to a separate class for testing
develohpanda 857044c
chore: refactor and move a few files around
develohpanda 925d8f6
test: repair existing tests that broke
develohpanda 29aeaf0
test: add tests for write-proto-file
develohpanda cfb89b6
test: add tests for ingesting a proto file
develohpanda f3e1887
test: move location of proto file fixtures, add integration test and …
develohpanda 3fbc367
fix: flaky test
develohpanda cd716bf
chore: remove old selector and related props
develohpanda f7105f8
test: add unit tests for redux proto selectors
develohpanda 478ebb1
test: add tests for proto manager add directory
develohpanda 19e57df
Merge branch 'develop' of github.com:Kong/insomnia into feature/ins-3…
develohpanda f50d1e1
Merge branch 'develop' of github.com:Kong/insomnia into feature/ins-3…
develohpanda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
packages/insomnia-app/app/__jest__/redux-state-for-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @flow | ||
|
||
import * as entities from '../ui/redux/modules/entities'; | ||
|
||
const reduxStateForTest = async (activeWorkspaceId: string): Promise<Object> => ({ | ||
entities: entities.reducer({}, entities.initializeWith(await entities.allDocs())), | ||
global: { activeWorkspaceId }, | ||
}); | ||
|
||
export default reduxStateForTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// @flow | ||
import * as db from '../common/database'; | ||
import type { BaseModel } from './index'; | ||
|
||
export const name = 'Proto Directory'; | ||
export const type = 'ProtoDirectory'; | ||
export const prefix = 'pd'; | ||
export const canDuplicate = true; | ||
export const canSync = true; | ||
|
||
type BaseProtoDirectory = { | ||
name: string, | ||
}; | ||
|
||
export type ProtoDirectory = BaseModel & BaseProtoDirectory; | ||
|
||
export function init(): BaseProtoDirectory { | ||
return { | ||
name: 'New Proto Directory', | ||
}; | ||
} | ||
|
||
export function migrate(doc: ProtoDirectory): ProtoDirectory { | ||
return doc; | ||
} | ||
|
||
export function create(patch: $Shape<ProtoDirectory> = {}): Promise<ProtoDirectory> { | ||
if (!patch.parentId) { | ||
throw new Error('New ProtoDirectory missing `parentId`'); | ||
} | ||
|
||
return db.docCreate(type, patch); | ||
} | ||
|
||
export function getById(_id: string): Promise<ProtoDirectory | null> { | ||
return db.getWhere(type, { _id }); | ||
} | ||
|
||
export function getByParentId(parentId: string): Promise<ProtoDirectory | null> { | ||
return db.getWhere(type, { parentId }); | ||
} | ||
|
||
export function remove(obj: ProtoDirectory): Promise<void> { | ||
return db.remove(obj); | ||
} | ||
|
||
export function all(): Promise<Array<ProtoDirectory>> { | ||
return db.all(type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
packages/insomnia-app/app/network/grpc/__fixtures__/library/nested/time/time.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
syntax = "proto3"; | ||
import "google/protobuf/timestamp.proto"; | ||
import "google/protobuf/empty.proto"; | ||
|
||
package time; | ||
|
||
service TimeService { | ||
rpc GetTime(google.protobuf.Empty) returns (TimeResponse); | ||
} | ||
|
||
message TimeResponse { | ||
google.protobuf.Timestamp timestamp_value = 27; | ||
} |
Empty file.
6 changes: 6 additions & 0 deletions
6
packages/insomnia-app/app/network/grpc/__fixtures__/library/root.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
syntax = "proto3"; | ||
|
||
package lib; | ||
|
||
import public 'hello.proto'; | ||
import public 'nested/time/time.proto'; |
93 changes: 93 additions & 0 deletions
93
packages/insomnia-app/app/network/grpc/__tests__/proto-integration.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// @flow | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
import * as protoManager from '../proto-manager'; | ||
import * as protoLoader from '../proto-loader'; | ||
import * as models from '../../../models'; | ||
import { globalBeforeEach } from '../../../__jest__/before-each'; | ||
import selectFileOrFolder from '../../../common/select-file-or-folder'; | ||
|
||
jest.mock('../../../common/select-file-or-folder', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
describe('proto management integration test', () => { | ||
beforeEach(globalBeforeEach); | ||
|
||
it('can ingest proto file and load methods from it', async () => { | ||
const w = await models.workspace.create(); | ||
|
||
// Mock folder selection | ||
const protoFilePath = path.join(__dirname, '../__fixtures__/library/hello.proto'); | ||
selectFileOrFolder.mockResolvedValue({ filePath: protoFilePath }); | ||
|
||
// Ingest into database | ||
let createdProtoFileId; | ||
await protoManager.addFile(w._id, id => { | ||
createdProtoFileId = id; | ||
}); | ||
|
||
expect(selectFileOrFolder).toHaveBeenCalledWith({ | ||
itemTypes: ['file'], | ||
extensions: ['proto'], | ||
}); | ||
|
||
// Find proto file entries | ||
const helloProto = await models.protoFile.getById(createdProtoFileId); | ||
|
||
// Load protoMethods | ||
const helloMethods = await protoLoader.loadMethods(helloProto); | ||
|
||
expect(helloMethods.length).toBe(4); | ||
}); | ||
|
||
it('can ingest proto directory tree and load methods from any file', async () => { | ||
const w = await models.workspace.create(); | ||
|
||
// Mock folder selection | ||
const libraryDirPath = path.join(__dirname, '../__fixtures__/library'); | ||
selectFileOrFolder.mockResolvedValue({ filePath: libraryDirPath }); | ||
|
||
// Ingest into database | ||
await protoManager.addDirectory(w._id); | ||
|
||
expect(selectFileOrFolder).toHaveBeenCalledWith({ | ||
itemTypes: ['directory'], | ||
extensions: ['proto'], | ||
}); | ||
|
||
// Find proto file entries | ||
const protoFiles = await models.protoFile.all(); | ||
const rootProto = protoFiles.find(pf => pf.name === 'root.proto'); | ||
const helloProto = protoFiles.find(pf => pf.name === 'hello.proto'); | ||
const timeProto = protoFiles.find(pf => pf.name === 'time.proto'); | ||
|
||
// Load protoMethods | ||
const rootMethods = await protoLoader.loadMethods(rootProto); | ||
const helloMethods = await protoLoader.loadMethods(helloProto); | ||
const timeMethods = await protoLoader.loadMethods(timeProto); | ||
|
||
expect(rootMethods.length).toBe(helloMethods.length + timeMethods.length); | ||
expect(helloMethods.length).toBe(4); | ||
expect(timeMethods.length).toBe(1); | ||
|
||
// Create request | ||
const gr = await models.grpcRequest.create({ | ||
parentId: w._id, | ||
protoFileId: rootProto._id, | ||
protoMethodName: rootMethods[0].path, | ||
}); | ||
|
||
// Load selected method | ||
const selectedMethod = await protoLoader.getSelectedMethod(gr); | ||
|
||
expect(JSON.stringify(selectedMethod)).toEqual(JSON.stringify(rootMethods[0])); | ||
}); | ||
|
||
afterEach(async () => { | ||
const tempDirPath = path.join(os.tmpdir(), 'insomnia-grpc'); | ||
await fs.promises.rmdir(tempDirPath, { recursive: true }); | ||
}); | ||
}); |
39 changes: 0 additions & 39 deletions
39
packages/insomnia-app/app/network/grpc/__tests__/proto-loader.test.js
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...pp/network/grpc/__mocks__/proto-loader.js → ...work/grpc/proto-loader/__mocks__/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
loadMethods: jest.fn(), | ||
loadMethodsFromPath: jest.fn(), | ||
getSelectedMethod: jest.fn(), | ||
}; |
54 changes: 54 additions & 0 deletions
54
packages/insomnia-app/app/network/grpc/proto-loader/__tests__/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @flow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import * as protoLoader from '../index'; | ||
import writeProtoFile from '../write-proto-file'; | ||
import path from 'path'; | ||
import { globalBeforeEach } from '../../../../__jest__/before-each'; | ||
import * as models from '../../../../models'; | ||
|
||
jest.mock('../write-proto-file', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
describe('loadMethods', () => { | ||
const protoFilePath = path.join(__dirname, '../../__fixtures__/library/hello.proto'); | ||
|
||
beforeEach(() => { | ||
globalBeforeEach(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should load methods', async () => { | ||
const w = await models.workspace.create(); | ||
const pf = await models.protoFile.create({ | ||
parentId: w._id, | ||
protoText: 'this is just a placeholder because writing to a file is mocked', | ||
}); | ||
writeProtoFile.mockResolvedValue({ filePath: protoFilePath, dirs: [] }); | ||
|
||
const methods = await protoLoader.loadMethods(pf); | ||
|
||
expect(writeProtoFile).toHaveBeenCalledWith(pf); | ||
|
||
expect(methods).toHaveLength(4); | ||
expect(methods.map(c => c.path)).toStrictEqual( | ||
expect.arrayContaining([ | ||
'/hello.HelloService/SayHello', | ||
'/hello.HelloService/LotsOfReplies', | ||
'/hello.HelloService/LotsOfGreetings', | ||
'/hello.HelloService/BidiHello', | ||
]), | ||
); | ||
}); | ||
|
||
it('should load no methods if protofile does not exist or is empty', async () => { | ||
const w = await models.workspace.create(); | ||
const pf = await models.protoFile.create({ | ||
parentId: w._id, | ||
protoText: '', | ||
}); | ||
|
||
await expect(protoLoader.loadMethods(undefined)).resolves.toHaveLength(0); | ||
await expect(protoLoader.loadMethods(pf)).resolves.toHaveLength(0); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.