Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmd/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"context"
"errors"
"fmt"
"go/ast"
"go/doc"
Expand All @@ -44,14 +45,27 @@ func createFunctionCmd() (c *cobra.Command) {
}
flags := c.Flags()
flags.StringVarP(&opt.feature, "feature", "", "", "The feature query")
flags.StringVarP(&opt.extensionFile, "extension-file", "", "", "The extension file")
return
}

type funcPrinterOption struct {
feature string
feature string
extensionFile string
}

func (o *funcPrinterOption) runE(cmd *cobra.Command, args []string) (err error) {
if o.extensionFile != "" {
var tpl *render.UserDefinedTemplates
if tpl, err = render.ParseUserDefinedTemplatesFromFile(o.extensionFile); err != nil {
return
}

if err = errors.Join(err, tpl.Validate(), tpl.ConflictWith(render.FuncMap())); err != nil {
return
}
}

if len(args) > 0 {
name := args[0]
filterAndPrint(cmd, name)
Expand Down
15 changes: 14 additions & 1 deletion cmd/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestCreateFunctionCommand(t *testing.T) {
tests := []struct {
name string
args []string
hasErr bool
verify func(t *testing.T, output string)
}{{
name: "normal",
Expand Down Expand Up @@ -61,6 +62,13 @@ func TestCreateFunctionCommand(t *testing.T) {
assert.Equal(t, `{{generateJSONString "name"}}
`, output)
},
}, {
name: "verify template functions with error",
args: []string{"func", "--extension-file", "testdata/function-with-conflicts.yaml"},
hasErr: true,
verify: func(t *testing.T, output string) {
assert.Contains(t, output, "conflict with existing function")
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -69,10 +77,15 @@ func TestCreateFunctionCommand(t *testing.T) {

buf := new(bytes.Buffer)
c.SetOut(buf)
c.SetErr(buf)
c.SetArgs(tt.args)

err := c.Execute()
assert.NoError(t, err)
if tt.hasErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}

if tt.verify != nil {
tt.verify(t, buf.String())
Expand Down
4 changes: 4 additions & 0 deletions cmd/testdata/function-with-conflicts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
items:
- name: randEnum
render: |
{{ randInt 18 60 }}
9 changes: 2 additions & 7 deletions console/atest-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Guide,
DataAnalysis, Help, Setting
} from '@element-plus/icons-vue'
import * as ElementPlusIcons from '@element-plus/icons-vue'
import { ref, watch, getCurrentInstance} from 'vue'
import { API } from './views/net'
import { Cache } from './views/cache'
Expand All @@ -16,7 +17,6 @@ import TestingHistoryPanel from './views/TestingHistoryPanel.vue'
import MockManager from './views/MockManager.vue'
import StoreManager from './views/StoreManager.vue'
import WelcomePage from './views/WelcomePage.vue'
import DataManager from './views/DataManager.vue'
import MagicKey from './components/MagicKey.vue'
import Extension from './views/Extension.vue'
import { useI18n } from 'vue-i18n'
Expand Down Expand Up @@ -152,17 +152,13 @@ API.GetMenus((menus) => {
<el-icon><Guide /></el-icon>
<template #title>{{ t('title.mock' )}}</template>
</el-menu-item>
<el-menu-item index="data" test-id="data-menu">
<el-icon><DataAnalysis /></el-icon>
<template #title>{{ t('title.data' )}}</template>
</el-menu-item>
<el-menu-item index="store">
<el-icon><location /></el-icon>
<template #title>{{ t('title.stores') }}</template>
</el-menu-item>
<span v-for="menu in extensionMenus" :key="menu.index" :index="menu.index">
<el-menu-item :index="menu.index">
<el-icon><IconMenu /></el-icon>
<el-icon><component :is="ElementPlusIcons[menu.icon]" /></el-icon>
<template #title>{{ menu.name }}</template>
</el-menu-item>
</span>
Expand All @@ -177,7 +173,6 @@ API.GetMenus((menus) => {
</div>
<TestingPanel v-if="panelName === 'testing'" @toHistoryPanel="toHistoryPanel"/>
<TestingHistoryPanel v-else-if="panelName === 'history'" :ID="ID"/>
<DataManager v-else-if="panelName === 'data'" />
<MockManager v-else-if="panelName === 'mock'" />
<StoreManager v-else-if="panelName === 'store'" />
<WelcomePage v-else-if="panelName === 'welcome' || panelName === ''" />
Expand Down
Loading
Loading