Skip to content

Commit

Permalink
Fix http header reader in Go runner (#151)
Browse files Browse the repository at this point in the history
* Fix http heaer

* Fix for format
  • Loading branch information
eatonphil committed Jan 17, 2022
1 parent c9beec2 commit 63dcf5c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 39 deletions.
96 changes: 62 additions & 34 deletions desktop/panel/http.test.js
Expand Up @@ -32,6 +32,7 @@ const USERDATA_FILES = ['json', 'xlsx', 'csv', 'parquet', 'jsonl'];
const PORT = '9799';

let server;
// Kill the existing server if it wasn't killed correctly already.
beforeAll(async () => {
// TODO: port this logic to other platforms...
if (process.platform === 'linux') {
Expand All @@ -44,6 +45,7 @@ beforeAll(async () => {
}
}

// Start a new server for all tests
server = spawn('python3', ['-m', 'http.server', PORT]);
let ready = false;
server.on('spawn', () => {
Expand Down Expand Up @@ -206,43 +208,69 @@ for (const subprocessName of RUNNERS) {
}

if (process.platform === 'linux') {
describe(
'eval file over server via ' +
(subprocessName ? subprocessName.go || subprocessName.node : 'memory'),
() => {
test('correct result', () => {
const server = new ServerInfo({
address: 'localhost',
type: 'private-key',
});
const hp = new HTTPPanelInfo(
'',
new HTTPConnectorInfo('', 'http://localhost:9799/testdata/unknown')
);
hp.serverId = server.id;
describe('http with headers', () => {
test('correct result', () => {
const hp = new HTTPPanelInfo(
'',
new HTTPConnectorInfo('', 'http://localhost:9799/testdata/unknown', [
{ name: 'X-Test', value: 'OK' },
])
);

const servers = [server];
const panels = [hp];
const panels = [hp];

return withSavedPanels(
panels,
(project) => {
// Grab result
const value = JSON.parse(
fs
.readFileSync(
getProjectResultsFile(project.projectName) + hp.id
)
.toString()
);
return withSavedPanels(
panels,
(project) => {
// Grab result
const value = JSON.parse(
fs
.readFileSync(
getProjectResultsFile(project.projectName) + hp.id
)
.toString()
);

expect(value).toEqual('hey this is unknown');
},
{ evalPanels: true, subprocessName, servers }
);
}, 30_000);
}
);
expect(value).toEqual('hey this is unknown');
},
{ evalPanels: true, subprocessName }
);
});
});

describe('eval http over server via ' + subprocessName.go, () => {
test('correct result', () => {
const server = new ServerInfo({
address: 'localhost',
type: 'private-key',
});
const hp = new HTTPPanelInfo(
'',
new HTTPConnectorInfo('', 'http://localhost:9799/testdata/unknown')
);
hp.serverId = server.id;

const servers = [server];
const panels = [hp];

return withSavedPanels(
panels,
(project) => {
// Grab result
const value = JSON.parse(
fs
.readFileSync(
getProjectResultsFile(project.projectName) + hp.id
)
.toString()
);

expect(value).toEqual('hey this is unknown');
},
{ evalPanels: true, subprocessName, servers }
);
}, 30_000);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion runner/http.go
Expand Up @@ -126,7 +126,7 @@ func evalHttpPanel(project *ProjectState, pageIndex int, panel *PanelInfo) error
}

for _, header := range h.Headers {
req.Header.Set(header[0], header[1])
req.Header.Set(header.Name, header.Value)
}

client := &http.Client{}
Expand Down
13 changes: 9 additions & 4 deletions runner/state.go
Expand Up @@ -285,11 +285,16 @@ type DatabaseConnectorInfo struct {
Database DatabaseConnectorInfoDatabase `json:"database" db:"database"`
}

type HttpConnectorInfoHeader struct {
Name string `json:"name"`
Value string `json:"value"`
}

type HttpConnectorInfoHttp struct {
Method string `json:"method" db:"method"`
Url string `json:"url" db:"url"`
ContentTypeInfo ContentTypeInfo `json:"contentTypeInfo" db:"contentTypeInfo"`
Headers [][]string `json:"headers" db:"headers"`
Method string `json:"method" db:"method"`
Url string `json:"url" db:"url"`
ContentTypeInfo ContentTypeInfo `json:"contentTypeInfo" db:"contentTypeInfo"`
Headers []HttpConnectorInfoHeader `json:"headers" db:"headers"`
}

type HttpConnectorInfo struct {
Expand Down

0 comments on commit 63dcf5c

Please sign in to comment.