MCPcopy Create free account
hub / github.com/github/gh-aw / TestExtractActionMetadata

Function TestExtractActionMetadata

pkg/cli/generate_action_metadata_command_test.go:29–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestExtractActionMetadata(t *testing.T) {
30 tests := []struct {
31 name string
32 filename string
33 content string
34 expectError bool
35 checkFields func(*testing.T, *ActionMetadata)
36 }{
37 {
38 name: "simple noop action",
39 filename: "noop.cjs",
40 content: `/**
41 * @description Does nothing, used for testing
42 */
43module.exports = async function noop() {
44 console.log('noop');
45};`,
46 expectError: false,
47 checkFields: func(t *testing.T, metadata *ActionMetadata) {
48 assert.Equal(t, "noop", metadata.ActionName, "Action name should be 'noop'")
49 assert.Equal(t, "noop.cjs", metadata.Filename, "Filename should be 'noop.cjs'")
50 assert.Contains(t, metadata.Description, "Does nothing", "Description should contain expected text")
51 },
52 },
53 {
54 name: "action with inputs",
55 filename: "test.cjs",
56 content: `/**
57 * @description Test action with inputs
58 * @param {string} input1 - First input
59 * @param {boolean} required_input - Required input
60 */
61module.exports = async function test(input1, required_input) {
62 return { output: 'value' };
63};`,
64 expectError: false,
65 checkFields: func(t *testing.T, metadata *ActionMetadata) {
66 assert.Equal(t, "test", metadata.ActionName, "Action name should be 'test'")
67 },
68 },
69 {
70 name: "action without description",
71 filename: "undocumented.cjs",
72 content: `module.exports = async function undocumented() {
73 return {};
74};`,
75 expectError: false,
76 checkFields: func(t *testing.T, metadata *ActionMetadata) {
77 assert.Equal(t, "undocumented", metadata.ActionName, "Action name should be 'undocumented'")
78 assert.NotEmpty(t, metadata.Description, "Should generate a default description")
79 },
80 },
81 }
82
83 for _, tt := range tests {
84 t.Run(tt.name, func(t *testing.T) {
85 metadata, err := extractActionMetadata(tt.filename, tt.content)
86

Callers

nothing calls this directly

Calls 3

extractActionMetadataFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected