From ba51c74b33a4b157b2fbaf28cc43acc18d3765c3 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Fri, 15 Dec 2023 12:32:18 +0800 Subject: [PATCH] chore: add favicon for the web page (#316) Co-authored-by: rick --- .github/workflows/build.yaml | 3 +++ Makefile | 2 +- cmd/data/favicon.ico | Bin 0 -> 3494 bytes cmd/server.go | 7 +++++++ cmd/server_test.go | 9 +++++++++ console/atest-ui/vite.config.ts | 18 +++++++++++++++++- e2e/test-suite-common.yaml | 7 +++++++ 7 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 cmd/data/favicon.ico diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8a71c00..35c2f9d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -54,6 +54,9 @@ jobs: sudo atest service install sudo atest service restart sudo atest service status + + # make test-ui-e2e + atest run -p '.github/testing/*.yaml' --request-ignore-error --report github --report-file bin/report.json --report-github-repo linuxsuren/api-testing --report-github-pr ${{ github.event.number }} sudo atest service status sudo atest service stop diff --git a/Makefile b/Makefile index 6799215..67ebb2f 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,7 @@ testlong: test-ui: cd console/atest-ui && npm run test:unit test-ui-e2e: - cd console/atest-ui && npm run test:e2e + cd console/atest-ui && npm i && npm run test:e2e test-collector: go test github.com/linuxsuren/api-testing/extensions/collector/./... -cover -v -coverprofile=collector-coverage.out go tool cover -func=collector-coverage.out diff --git a/cmd/data/favicon.ico b/cmd/data/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..5036269de88057b3b036a7546c20dab37f302be9 GIT binary patch literal 3494 zcmeHK?N6Ik6t91PU;UtoK~0RBxJ4wAEIP6+bBmeNIWsZYK(ma9A0&Q&gg3)Wcu9DV zCRpAnOB@0VFrXA@3#EnfCMr;%g@PT>(ifnBg%;?~=bYssybOa|O!k4(+Xmp z&bhzm=BY&TobU^HQ9`{W|9Oez1&KuRhR_0p79=!UXA$;ZJN2kNT98QajLOc=4z{%QSiW-duBO@ccM9*3M`dLthKGldk&(gk zl9CcEFE6v6N~Oa1_&7hewY4EOHWnt63G_TSH^=ej$at%Zq@k3lEuYER99CcGBT3Sys@#7>qO^&@7_I*U8mD=JsKJsKy~Wt>tmaUhzKMm zCW34z#_;fPSglq*;h(F#qbL?5Swph8M+&nF_D|bcnbo)>fAf<%s+fAJ}u7GS3~__FuX43 zkvfmtn8;7(+y)}PME{*o^hboE_tqz9Kl3J*ejj8L!dHfzhTAX#ifzZcdC1kn`@abI z?_txvcxdn676_v)_;naEe}Lsz87$Q@Xs=&HZ}>HAZ+O_$D%4m0_Dj%Q4H4>c3Hq-; z$4pf*w$|5oT|X&4Vd%fQ4wJNieG$hrpPqxcQo8GVp{)rWXWqj6gE~00YM3j2hU!8P zpO0VoZXkJ5e6lrHNTCb;2-}{&VeM#v>HsIj^WU(}lRC@H-4fOlIq@|3YttsEF9pNV zqro3>-(e`~Hgi$L67fYWTDNt`nIo&F308X=eB%9Y-`_$1H#eEX^G)|fXdXrWtxk;b z9YF8vz_+*f9U(sYw|w|Z;EnoX5Wk~-;oI!L%0f#$GvJ)sDE1=?%p zq5I-8x~_bHo|{+U8q~AijI0QnEAK<`?yKk%?tzuDKlj-mXR@`v24}AZZn8b_UFmf> v;Lvr#uIYeX;NSAdFyBj}-&Lal_O1@*roCGQ?~+U0IvJm#3W)!M{_pW0n=#MZ literal 0 HcmV?d00001 diff --git a/cmd/server.go b/cmd/server.go index fbfb00f..086a6f5 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -255,6 +255,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) { mux.HandlePath(http.MethodGet, "/", frontEndHandlerWithLocation(o.consolePath)) mux.HandlePath(http.MethodGet, "/assets/{asset}", frontEndHandlerWithLocation(o.consolePath)) mux.HandlePath(http.MethodGet, "/healthz", frontEndHandlerWithLocation(o.consolePath)) + mux.HandlePath(http.MethodGet, "/favicon.ico", frontEndHandlerWithLocation(o.consolePath)) mux.HandlePath(http.MethodGet, "/get", o.getAtestBinary) postRequestProxyFunc := postRequestProxy(o.skyWalking) @@ -340,6 +341,9 @@ func frontEndHandlerWithLocation(consolePath string) func(w http.ResponseWriter, case strings.HasSuffix(target, ".css"): content = uiResourceCSS customHeader[util.ContentType] = "text/css" + case strings.HasSuffix(target, ".ico"): + content = uiResourceIcon + customHeader[util.ContentType] = "image/x-icon" } if content != "" { @@ -447,3 +451,6 @@ var uiResourceCSS string //go:embed data/index.html var uiResourceIndex string + +//go:embed data/favicon.ico +var uiResourceIcon string diff --git a/cmd/server_test.go b/cmd/server_test.go index e2ef807..4d88cd8 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -117,6 +117,15 @@ func TestFrontEndHandlerWithLocation(t *testing.T) { assert.Equal(t, expect404, resp.GetBody().String()) }) + t.Run("favicon", func(t *testing.T) { + req, err := http.NewRequest(http.MethodGet, "/favicon.ico", nil) + assert.NoError(t, err) + + resp := newFakeResponseWriter() + handler(resp, req, map[string]string{}) + assert.Equal(t, "image/x-icon", resp.Header().Get(util.ContentType)) + }) + t.Run("healthz", func(t *testing.T) { req, err := http.NewRequest(http.MethodGet, "/healthz", nil) assert.NoError(t, err) diff --git a/console/atest-ui/vite.config.ts b/console/atest-ui/vite.config.ts index da7895f..e988ed2 100644 --- a/console/atest-ui/vite.config.ts +++ b/console/atest-ui/vite.config.ts @@ -4,10 +4,26 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueJsx from '@vitejs/plugin-vue-jsx' +function removeDataTestAttrs(node) { + if (node.type === 1 /* NodeTypes.ELEMENT */) { + node.props = node.props.filter(prop => + prop.type === 6 /* NodeTypes.ATTRIBUTE */ + ? prop.name !== 'test-id' + : true + ) + } +} + // https://vitejs.dev/config/ export default defineConfig({ plugins: [ - vue(), + vue({ + template: { + compilerOptions: { + nodeTransforms: true ? [removeDataTestAttrs] : [], + }, + }, + }), vueJsx(), ], resolve: { diff --git a/e2e/test-suite-common.yaml b/e2e/test-suite-common.yaml index cb1a65d..4d4ac03 100644 --- a/e2e/test-suite-common.yaml +++ b/e2e/test-suite-common.yaml @@ -286,3 +286,10 @@ items: request: api: | {{.param.server}}/debug/pprof/cmdline +- name: favicon + request: + api: | + {{ .param.server }}/favicon.ico + expect: + header: + Content-Type: image/x-icon