Best K6 code snippet using html.Sizes
subpath_test.go
Source:subpath_test.go
1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.2// See LICENSE.txt for license information.3package utils_test4import (5 "fmt"6 "io/ioutil"7 "os"8 "path/filepath"9 "strings"10 "testing"11 "github.com/stretchr/testify/require"12 "github.com/mattermost/mattermost-server/v6/model"13 "github.com/mattermost/mattermost-server/v6/utils"14)15func TestUpdateAssetsSubpathFromConfig(t *testing.T) {16 t.Run("dev build", func(t *testing.T) {17 var oldBuildNumber = model.BuildNumber18 model.BuildNumber = "dev"19 defer func() {20 model.BuildNumber = oldBuildNumber21 }()22 err := utils.UpdateAssetsSubpathFromConfig(nil)23 require.NoError(t, err)24 })25 t.Run("IS_CI=true", func(t *testing.T) {26 err := os.Setenv("IS_CI", "true")27 require.NoError(t, err)28 defer func() {29 os.Unsetenv("IS_CI")30 }()31 err = utils.UpdateAssetsSubpathFromConfig(nil)32 require.NoError(t, err)33 })34 t.Run("no config", func(t *testing.T) {35 tempDir, err := ioutil.TempDir("", "test_update_assets_subpath")36 require.NoError(t, err)37 defer os.RemoveAll(tempDir)38 os.Chdir(tempDir)39 err = utils.UpdateAssetsSubpathFromConfig(nil)40 require.Error(t, err)41 })42}43func TestUpdateAssetsSubpath(t *testing.T) {44 t.Run("no client dir", func(t *testing.T) {45 tempDir, err := ioutil.TempDir("", "test_update_assets_subpath")46 require.NoError(t, err)47 defer os.RemoveAll(tempDir)48 os.Chdir(tempDir)49 err = utils.UpdateAssetsSubpath("/")50 require.Error(t, err)51 })52 t.Run("valid", func(t *testing.T) {53 tempDir, err := ioutil.TempDir("", "test_update_assets_subpath")54 require.NoError(t, err)55 defer os.RemoveAll(tempDir)56 os.Chdir(tempDir)57 err = os.Mkdir(model.ClientDir, 0700)58 require.NoError(t, err)59 testCases := []struct {60 Description string61 RootHTML string62 MainCSS string63 ManifestJSON string64 Subpath string65 ExpectedError error66 ExpectedRootHTML string67 ExpectedMainCSS string68 ExpectedManifestJSON string69 }{70 {71 "no changes required, empty subpath provided",72 baseRootHTML,73 baseCSS,74 baseManifestJSON,75 "",76 nil,77 baseRootHTML,78 baseCSS,79 baseManifestJSON,80 },81 {82 "no changes required",83 baseRootHTML,84 baseCSS,85 baseManifestJSON,86 "/",87 nil,88 baseRootHTML,89 baseCSS,90 baseManifestJSON,91 },92 {93 "content security policy not found (missing quotes)",94 contentSecurityPolicyNotFoundHTML,95 baseCSS,96 baseManifestJSON,97 "/subpath",98 fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite"),99 contentSecurityPolicyNotFoundHTML,100 baseCSS,101 baseManifestJSON,102 },103 {104 "content security policy not found (missing unsafe-eval)",105 contentSecurityPolicyNotFound2HTML,106 baseCSS,107 baseManifestJSON,108 "/subpath",109 fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite"),110 contentSecurityPolicyNotFound2HTML,111 baseCSS,112 baseManifestJSON,113 },114 {115 "subpath",116 baseRootHTML,117 baseCSS,118 baseManifestJSON,119 "/subpath",120 nil,121 subpathRootHTML,122 subpathCSS,123 subpathManifestJSON,124 },125 {126 "new subpath from old",127 subpathRootHTML,128 subpathCSS,129 subpathManifestJSON,130 "/nested/subpath",131 nil,132 newSubpathRootHTML,133 newSubpathCSS,134 newSubpathManifestJSON,135 },136 {137 "resetting to /",138 subpathRootHTML,139 subpathCSS,140 baseManifestJSON,141 "/",142 nil,143 baseRootHTML,144 baseCSS,145 baseManifestJSON,146 },147 }148 for _, testCase := range testCases {149 t.Run(testCase.Description, func(t *testing.T) {150 ioutil.WriteFile(filepath.Join(tempDir, model.ClientDir, "root.html"), []byte(testCase.RootHTML), 0700)151 ioutil.WriteFile(filepath.Join(tempDir, model.ClientDir, "main.css"), []byte(testCase.MainCSS), 0700)152 ioutil.WriteFile(filepath.Join(tempDir, model.ClientDir, "manifest.json"), []byte(testCase.ManifestJSON), 0700)153 err := utils.UpdateAssetsSubpath(testCase.Subpath)154 if testCase.ExpectedError != nil {155 require.Equal(t, testCase.ExpectedError, err)156 } else {157 require.NoError(t, err)158 }159 contents, err := ioutil.ReadFile(filepath.Join(tempDir, model.ClientDir, "root.html"))160 require.NoError(t, err)161 // Rewrite the expected and contents for simpler diffs when failed.162 expectedRootHTML := strings.Replace(testCase.ExpectedRootHTML, ">", ">\n", -1)163 contentsStr := strings.Replace(string(contents), ">", ">\n", -1)164 require.Equal(t, expectedRootHTML, contentsStr)165 contents, err = ioutil.ReadFile(filepath.Join(tempDir, model.ClientDir, "main.css"))166 require.NoError(t, err)167 require.Equal(t, testCase.ExpectedMainCSS, string(contents))168 contents, err = ioutil.ReadFile(filepath.Join(tempDir, model.ClientDir, "manifest.json"))169 require.NoError(t, err)170 require.Equal(t, testCase.ExpectedManifestJSON, string(contents))171 })172 }173 })174}175func TestGetSubpathFromConfig(t *testing.T) {176 testCases := []struct {177 Description string178 SiteURL *string179 ExpectedError bool180 ExpectedSubpath string181 }{182 {183 "empty SiteURL",184 sToP(""),185 false,186 "/",187 },188 {189 "invalid SiteURL",190 sToP("cache_object:foo/bar"),191 true,192 "",193 },194 {195 "nil SiteURL",196 nil,197 false,198 "/",199 },200 {201 "no trailing slash",202 sToP("http://localhost:8065"),203 false,204 "/",205 },206 {207 "trailing slash",208 sToP("http://localhost:8065/"),209 false,210 "/",211 },212 {213 "subpath, no trailing slash",214 sToP("http://localhost:8065/subpath"),215 false,216 "/subpath",217 },218 {219 "trailing slash",220 sToP("http://localhost:8065/subpath/"),221 false,222 "/subpath",223 },224 }225 for _, testCase := range testCases {226 t.Run(testCase.Description, func(t *testing.T) {227 config := &model.Config{228 ServiceSettings: model.ServiceSettings{229 SiteURL: testCase.SiteURL,230 },231 }232 subpath, err := utils.GetSubpathFromConfig(config)233 if testCase.ExpectedError {234 require.Error(t, err)235 } else {236 require.NoError(t, err)237 }238 require.Equal(t, testCase.ExpectedSubpath, subpath)239 })240 }241}242func sToP(s string) *string {243 return &s244}245const contentSecurityPolicyNotFoundHTML = `<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <meta http-equiv=Content-Security-Policy content="script-src 'self' cdn.rudderlabs.com/ js.stripe.com/v3"> <meta http-equiv=X-UA-Compatible content="IE=edge"> <meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"> <meta name=robots content="noindex, nofollow"> <meta name=referrer content=no-referrer> <title>Mattermost</title> <meta name=apple-mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-status-bar-style content=default> <meta name=mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-title content=Mattermost> <meta name=application-name content=Mattermost> <meta name=format-detection content="telephone=no"> <link rel=apple-touch-icon sizes=57x57 href=/static/files/78b7e73b41b8731ce2c41c870ecc8886.png> <link rel=apple-touch-icon sizes=60x60 href=/static/files/51d00ffd13afb6d74fd8f6dfdeef768a.png> <link rel=apple-touch-icon sizes=72x72 href=/static/files/23645596f8f78f017bd4d457abb855c4.png> <link rel=apple-touch-icon sizes=76x76 href=/static/files/26e9d72f472663a00b4b206149459fab.png> <link rel=apple-touch-icon sizes=144x144 href=/static/files/7bd91659bf3fc8c68fcd45fc1db9c630.png> <link rel=apple-touch-icon sizes=120x120 href=/static/files/fa69ffe11eb334aaef5aece8d848ca62.png> <link rel=apple-touch-icon sizes=152x152 href=/static/files/f046777feb6ab12fc43b8f9908b1db35.png> <link rel=icon type=image/png sizes=16x16 href=/static/files/02b96247d275680adaaabf01c71c571d.png> <link rel=icon type=image/png sizes=32x32 href=/static/files/1d9020f201a6762421cab8d30624fdd8.png> <link rel=icon type=image/png sizes=96x96 href=/static/files/fe23af39ae98d77dc26ae8586565970f.png> <link rel=icon type=image/png sizes=192x192 href=/static/files/d7ff68a7675f84337cc154c3d4abe713.png> <link rel=manifest href=/static/files/a985ad72552ad069537d6eea81e719c7.json> <link rel=stylesheet class=code_theme> <style>.error-screen{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;padding-top:50px;max-width:750px;font-size:14px;color:#333;margin:auto;display:none;line-height:1.5}.error-screen h2{font-size:30px;font-weight:400;line-height:1.2}.error-screen ul{padding-left:15px;line-height:1.7;margin-top:0;margin-bottom:10px}.error-screen hr{color:#ddd;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.error-screen-visible{display:block}</style> <link href="/static/main.364fd054d7a6d741efc6.css" rel="stylesheet"><script type="text/javascript" src="/static/main.e49599ac425584ffead5.js"></script></head> <body class=font--open_sans> <div id=root> <div class=error-screen> <h2>Cannot connect to Mattermost</h2> <hr/> <p>We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.</p> <br/> </div> <div class=loading-screen style=position:relative> <div class=loading__content> <div class="round round-1"></div> <div class="round round-2"></div> <div class="round round-3"></div> </div> </div> </div> <noscript> To use Mattermost, please enable JavaScript. </noscript> </body> </html>`246const contentSecurityPolicyNotFound2HTML = `<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <meta http-equiv=Content-Security-Policy content="script-src 'self' cdn.rudderlabs.com/ js.stripe.com/v3 'unsafe-eval'"> <meta http-equiv=X-UA-Compatible content="IE=edge"> <meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"> <meta name=robots content="noindex, nofollow"> <meta name=referrer content=no-referrer> <title>Mattermost</title> <meta name=apple-mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-status-bar-style content=default> <meta name=mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-title content=Mattermost> <meta name=application-name content=Mattermost> <meta name=format-detection content="telephone=no"> <link rel=apple-touch-icon sizes=57x57 href=/static/files/78b7e73b41b8731ce2c41c870ecc8886.png> <link rel=apple-touch-icon sizes=60x60 href=/static/files/51d00ffd13afb6d74fd8f6dfdeef768a.png> <link rel=apple-touch-icon sizes=72x72 href=/static/files/23645596f8f78f017bd4d457abb855c4.png> <link rel=apple-touch-icon sizes=76x76 href=/static/files/26e9d72f472663a00b4b206149459fab.png> <link rel=apple-touch-icon sizes=144x144 href=/static/files/7bd91659bf3fc8c68fcd45fc1db9c630.png> <link rel=apple-touch-icon sizes=120x120 href=/static/files/fa69ffe11eb334aaef5aece8d848ca62.png> <link rel=apple-touch-icon sizes=152x152 href=/static/files/f046777feb6ab12fc43b8f9908b1db35.png> <link rel=icon type=image/png sizes=16x16 href=/static/files/02b96247d275680adaaabf01c71c571d.png> <link rel=icon type=image/png sizes=32x32 href=/static/files/1d9020f201a6762421cab8d30624fdd8.png> <link rel=icon type=image/png sizes=96x96 href=/static/files/fe23af39ae98d77dc26ae8586565970f.png> <link rel=icon type=image/png sizes=192x192 href=/static/files/d7ff68a7675f84337cc154c3d4abe713.png> <link rel=manifest href=/static/files/a985ad72552ad069537d6eea81e719c7.json> <link rel=stylesheet class=code_theme> <style>.error-screen{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;padding-top:50px;max-width:750px;font-size:14px;color:#333;margin:auto;display:none;line-height:1.5}.error-screen h2{font-size:30px;font-weight:400;line-height:1.2}.error-screen ul{padding-left:15px;line-height:1.7;margin-top:0;margin-bottom:10px}.error-screen hr{color:#ddd;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.error-screen-visible{display:block}</style> <link href="/static/main.364fd054d7a6d741efc6.css" rel="stylesheet"><script type="text/javascript" src="/static/main.e49599ac425584ffead5.js"></script></head> <body class=font--open_sans> <div id=root> <div class=error-screen> <h2>Cannot connect to Mattermost</h2> <hr/> <p>We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.</p> <br/> </div> <div class=loading-screen style=position:relative> <div class=loading__content> <div class="round round-1"></div> <div class="round round-2"></div> <div class="round round-3"></div> </div> </div> </div> <noscript> To use Mattermost, please enable JavaScript. </noscript> </body> </html>`247const baseRootHTML = `<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <meta http-equiv="Content-Security-Policy" content="script-src 'self' cdn.rudderlabs.com/ js.stripe.com/v3"> <meta http-equiv=X-UA-Compatible content="IE=edge"> <meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"> <meta name=robots content="noindex, nofollow"> <meta name=referrer content=no-referrer> <title>Mattermost</title> <meta name=apple-mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-status-bar-style content=default> <meta name=mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-title content=Mattermost> <meta name=application-name content=Mattermost> <meta name=format-detection content="telephone=no"> <link rel=apple-touch-icon sizes=57x57 href=/static/files/78b7e73b41b8731ce2c41c870ecc8886.png> <link rel=apple-touch-icon sizes=60x60 href=/static/files/51d00ffd13afb6d74fd8f6dfdeef768a.png> <link rel=apple-touch-icon sizes=72x72 href=/static/files/23645596f8f78f017bd4d457abb855c4.png> <link rel=apple-touch-icon sizes=76x76 href=/static/files/26e9d72f472663a00b4b206149459fab.png> <link rel=apple-touch-icon sizes=144x144 href=/static/files/7bd91659bf3fc8c68fcd45fc1db9c630.png> <link rel=apple-touch-icon sizes=120x120 href=/static/files/fa69ffe11eb334aaef5aece8d848ca62.png> <link rel=apple-touch-icon sizes=152x152 href=/static/files/f046777feb6ab12fc43b8f9908b1db35.png> <link rel=icon type=image/png sizes=16x16 href=/static/files/02b96247d275680adaaabf01c71c571d.png> <link rel=icon type=image/png sizes=32x32 href=/static/files/1d9020f201a6762421cab8d30624fdd8.png> <link rel=icon type=image/png sizes=96x96 href=/static/files/fe23af39ae98d77dc26ae8586565970f.png> <link rel=icon type=image/png sizes=192x192 href=/static/files/d7ff68a7675f84337cc154c3d4abe713.png> <link rel=manifest href=/static/files/a985ad72552ad069537d6eea81e719c7.json> <link rel=stylesheet class=code_theme> <style>.error-screen{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;padding-top:50px;max-width:750px;font-size:14px;color:#333;margin:auto;display:none;line-height:1.5}.error-screen h2{font-size:30px;font-weight:400;line-height:1.2}.error-screen ul{padding-left:15px;line-height:1.7;margin-top:0;margin-bottom:10px}.error-screen hr{color:#ddd;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.error-screen-visible{display:block}</style> <link href="/static/main.364fd054d7a6d741efc6.css" rel="stylesheet"><script type="text/javascript" src="/static/main.e49599ac425584ffead5.js"></script></head> <body class=font--open_sans> <div id=root> <div class=error-screen> <h2>Cannot connect to Mattermost</h2> <hr/> <p>We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.</p> <br/> </div> <div class=loading-screen style=position:relative> <div class=loading__content> <div class="round round-1"></div> <div class="round round-2"></div> <div class="round round-3"></div> </div> </div> </div> <noscript> To use Mattermost, please enable JavaScript. </noscript> </body> </html>`248const baseCSS = `@font-face{font-family:FontAwesome;src:url(/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}`249const subpathRootHTML = `<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <meta http-equiv="Content-Security-Policy" content="script-src 'self' cdn.rudderlabs.com/ js.stripe.com/v3 'sha256-tPOjw+tkVs9axL78ZwGtYl975dtyPHB6LYKAO2R3gR4='"> <meta http-equiv=X-UA-Compatible content="IE=edge"> <meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"> <meta name=robots content="noindex, nofollow"> <meta name=referrer content=no-referrer> <title>Mattermost</title> <meta name=apple-mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-status-bar-style content=default> <meta name=mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-title content=Mattermost> <meta name=application-name content=Mattermost> <meta name=format-detection content="telephone=no"> <link rel=apple-touch-icon sizes=57x57 href=/subpath/static/files/78b7e73b41b8731ce2c41c870ecc8886.png> <link rel=apple-touch-icon sizes=60x60 href=/subpath/static/files/51d00ffd13afb6d74fd8f6dfdeef768a.png> <link rel=apple-touch-icon sizes=72x72 href=/subpath/static/files/23645596f8f78f017bd4d457abb855c4.png> <link rel=apple-touch-icon sizes=76x76 href=/subpath/static/files/26e9d72f472663a00b4b206149459fab.png> <link rel=apple-touch-icon sizes=144x144 href=/subpath/static/files/7bd91659bf3fc8c68fcd45fc1db9c630.png> <link rel=apple-touch-icon sizes=120x120 href=/subpath/static/files/fa69ffe11eb334aaef5aece8d848ca62.png> <link rel=apple-touch-icon sizes=152x152 href=/subpath/static/files/f046777feb6ab12fc43b8f9908b1db35.png> <link rel=icon type=image/png sizes=16x16 href=/subpath/static/files/02b96247d275680adaaabf01c71c571d.png> <link rel=icon type=image/png sizes=32x32 href=/subpath/static/files/1d9020f201a6762421cab8d30624fdd8.png> <link rel=icon type=image/png sizes=96x96 href=/subpath/static/files/fe23af39ae98d77dc26ae8586565970f.png> <link rel=icon type=image/png sizes=192x192 href=/subpath/static/files/d7ff68a7675f84337cc154c3d4abe713.png> <link rel=manifest href=/subpath/static/files/a985ad72552ad069537d6eea81e719c7.json> <link rel=stylesheet class=code_theme> <style>.error-screen{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;padding-top:50px;max-width:750px;font-size:14px;color:#333;margin:auto;display:none;line-height:1.5}.error-screen h2{font-size:30px;font-weight:400;line-height:1.2}.error-screen ul{padding-left:15px;line-height:1.7;margin-top:0;margin-bottom:10px}.error-screen hr{color:#ddd;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.error-screen-visible{display:block}</style><script>window.publicPath='/subpath/static/'</script> <link href="/subpath/static/main.364fd054d7a6d741efc6.css" rel="stylesheet"><script type="text/javascript" src="/subpath/static/main.e49599ac425584ffead5.js"></script></head> <body class=font--open_sans> <div id=root> <div class=error-screen> <h2>Cannot connect to Mattermost</h2> <hr/> <p>We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.</p> <br/> </div> <div class=loading-screen style=position:relative> <div class=loading__content> <div class="round round-1"></div> <div class="round round-2"></div> <div class="round round-3"></div> </div> </div> </div> <noscript> To use Mattermost, please enable JavaScript. </noscript> </body> </html>`250const subpathCSS = `@font-face{font-family:FontAwesome;src:url(/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/subpath/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/subpath/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/subpath/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/subpath/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}`251const newSubpathRootHTML = `<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <meta http-equiv="Content-Security-Policy" content="script-src 'self' cdn.rudderlabs.com/ js.stripe.com/v3 'sha256-mbRaPRRpWz6MNkX9SyXWMJ8XnWV4w/DoqK2M0ryUAvc='"> <meta http-equiv=X-UA-Compatible content="IE=edge"> <meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"> <meta name=robots content="noindex, nofollow"> <meta name=referrer content=no-referrer> <title>Mattermost</title> <meta name=apple-mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-status-bar-style content=default> <meta name=mobile-web-app-capable content=yes> <meta name=apple-mobile-web-app-title content=Mattermost> <meta name=application-name content=Mattermost> <meta name=format-detection content="telephone=no"> <link rel=apple-touch-icon sizes=57x57 href=/nested/subpath/static/files/78b7e73b41b8731ce2c41c870ecc8886.png> <link rel=apple-touch-icon sizes=60x60 href=/nested/subpath/static/files/51d00ffd13afb6d74fd8f6dfdeef768a.png> <link rel=apple-touch-icon sizes=72x72 href=/nested/subpath/static/files/23645596f8f78f017bd4d457abb855c4.png> <link rel=apple-touch-icon sizes=76x76 href=/nested/subpath/static/files/26e9d72f472663a00b4b206149459fab.png> <link rel=apple-touch-icon sizes=144x144 href=/nested/subpath/static/files/7bd91659bf3fc8c68fcd45fc1db9c630.png> <link rel=apple-touch-icon sizes=120x120 href=/nested/subpath/static/files/fa69ffe11eb334aaef5aece8d848ca62.png> <link rel=apple-touch-icon sizes=152x152 href=/nested/subpath/static/files/f046777feb6ab12fc43b8f9908b1db35.png> <link rel=icon type=image/png sizes=16x16 href=/nested/subpath/static/files/02b96247d275680adaaabf01c71c571d.png> <link rel=icon type=image/png sizes=32x32 href=/nested/subpath/static/files/1d9020f201a6762421cab8d30624fdd8.png> <link rel=icon type=image/png sizes=96x96 href=/nested/subpath/static/files/fe23af39ae98d77dc26ae8586565970f.png> <link rel=icon type=image/png sizes=192x192 href=/nested/subpath/static/files/d7ff68a7675f84337cc154c3d4abe713.png> <link rel=manifest href=/nested/subpath/static/files/a985ad72552ad069537d6eea81e719c7.json> <link rel=stylesheet class=code_theme> <style>.error-screen{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;padding-top:50px;max-width:750px;font-size:14px;color:#333;margin:auto;display:none;line-height:1.5}.error-screen h2{font-size:30px;font-weight:400;line-height:1.2}.error-screen ul{padding-left:15px;line-height:1.7;margin-top:0;margin-bottom:10px}.error-screen hr{color:#ddd;margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.error-screen-visible{display:block}</style><script>window.publicPath='/nested/subpath/static/'</script> <link href="/nested/subpath/static/main.364fd054d7a6d741efc6.css" rel="stylesheet"><script type="text/javascript" src="/nested/subpath/static/main.e49599ac425584ffead5.js"></script></head> <body class=font--open_sans> <div id=root> <div class=error-screen> <h2>Cannot connect to Mattermost</h2> <hr/> <p>We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.</p> <br/> </div> <div class=loading-screen style=position:relative> <div class=loading__content> <div class="round round-1"></div> <div class="round round-2"></div> <div class="round round-3"></div> </div> </div> </div> <noscript> To use Mattermost, please enable JavaScript. </noscript> </body> </html>`252const newSubpathCSS = `@font-face{font-family:FontAwesome;src:url(/nested/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/nested/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/nested/subpath/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/nested/subpath/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/nested/subpath/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/nested/subpath/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}`253const baseManifestJSON = `{254 "icons": [255 {256 "src": "/static/icon_96x96.png",257 "sizes": "96x96",258 "type": "image/png"259 },260 {261 "src": "/static/icon_32x32.png",262 "sizes": "32x32",263 "type": "image/png"264 },265 {266 "src": "/static/icon_16x16.png",267 "sizes": "16x16",268 "type": "image/png"269 },270 {271 "src": "/static/icon_76x76.png",272 "sizes": "76x76",273 "type": "image/png"274 },275 {276 "src": "/static/icon_72x72.png",277 "sizes": "72x72",278 "type": "image/png"279 },280 {281 "src": "/static/icon_60x60.png",282 "sizes": "60x60",283 "type": "image/png"284 },285 {286 "src": "/static/icon_57x57.png",287 "sizes": "57x57",288 "type": "image/png"289 },290 {291 "src": "/static/icon_152x152.png",292 "sizes": "152x152",293 "type": "image/png"294 },295 {296 "src": "/static/icon_144x144.png",297 "sizes": "144x144",298 "type": "image/png"299 },300 {301 "src": "/static/icon_120x120.png",302 "sizes": "120x120",303 "type": "image/png"304 },305 {306 "src": "/static/icon_192x192.png",307 "sizes": "192x192",308 "type": "image/png"309 }310 ],311 "name": "Mattermost",312 "short_name": "Mattermost",313 "orientation": "any",314 "display": "standalone",315 "start_url": ".",316 "description": "Mattermost is an open source, self-hosted Slack-alternative",317 "background_color": "#ffffff"318}319`320const subpathManifestJSON = `{321 "icons": [322 {323 "src": "/subpath/static/icon_96x96.png",324 "sizes": "96x96",325 "type": "image/png"326 },327 {328 "src": "/subpath/static/icon_32x32.png",329 "sizes": "32x32",330 "type": "image/png"331 },332 {333 "src": "/subpath/static/icon_16x16.png",334 "sizes": "16x16",335 "type": "image/png"336 },337 {338 "src": "/subpath/static/icon_76x76.png",339 "sizes": "76x76",340 "type": "image/png"341 },342 {343 "src": "/subpath/static/icon_72x72.png",344 "sizes": "72x72",345 "type": "image/png"346 },347 {348 "src": "/subpath/static/icon_60x60.png",349 "sizes": "60x60",350 "type": "image/png"351 },352 {353 "src": "/subpath/static/icon_57x57.png",354 "sizes": "57x57",355 "type": "image/png"356 },357 {358 "src": "/subpath/static/icon_152x152.png",359 "sizes": "152x152",360 "type": "image/png"361 },362 {363 "src": "/subpath/static/icon_144x144.png",364 "sizes": "144x144",365 "type": "image/png"366 },367 {368 "src": "/subpath/static/icon_120x120.png",369 "sizes": "120x120",370 "type": "image/png"371 },372 {373 "src": "/subpath/static/icon_192x192.png",374 "sizes": "192x192",375 "type": "image/png"376 }377 ],378 "name": "Mattermost",379 "short_name": "Mattermost",380 "orientation": "any",381 "display": "standalone",382 "start_url": ".",383 "description": "Mattermost is an open source, self-hosted Slack-alternative",384 "background_color": "#ffffff"385}386`387const newSubpathManifestJSON = `{388 "icons": [389 {390 "src": "/nested/subpath/static/icon_96x96.png",391 "sizes": "96x96",392 "type": "image/png"393 },394 {395 "src": "/nested/subpath/static/icon_32x32.png",396 "sizes": "32x32",397 "type": "image/png"398 },399 {400 "src": "/nested/subpath/static/icon_16x16.png",401 "sizes": "16x16",402 "type": "image/png"403 },404 {405 "src": "/nested/subpath/static/icon_76x76.png",406 "sizes": "76x76",407 "type": "image/png"408 },409 {410 "src": "/nested/subpath/static/icon_72x72.png",411 "sizes": "72x72",412 "type": "image/png"413 },414 {415 "src": "/nested/subpath/static/icon_60x60.png",416 "sizes": "60x60",417 "type": "image/png"418 },419 {420 "src": "/nested/subpath/static/icon_57x57.png",421 "sizes": "57x57",422 "type": "image/png"423 },424 {425 "src": "/nested/subpath/static/icon_152x152.png",426 "sizes": "152x152",427 "type": "image/png"428 },429 {430 "src": "/nested/subpath/static/icon_144x144.png",431 "sizes": "144x144",432 "type": "image/png"433 },434 {435 "src": "/nested/subpath/static/icon_120x120.png",436 "sizes": "120x120",437 "type": "image/png"438 },439 {440 "src": "/nested/subpath/static/icon_192x192.png",441 "sizes": "192x192",442 "type": "image/png"443 }444 ],445 "name": "Mattermost",446 "short_name": "Mattermost",447 "orientation": "any",448 "display": "standalone",449 "start_url": ".",450 "description": "Mattermost is an open source, self-hosted Slack-alternative",451 "background_color": "#ffffff"452}453`...
Sizes
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(os.Stdin)4 if err != nil {5 fmt.Fprintf(os.Stderr, "findlinks1: %v6 os.Exit(1)7 }8 for k, v := range visit(nil, doc) {9 fmt.Println(k, v)10 }11}12func visit(links map[string]int, n *html.Node) map[string]int {13 if links == nil {14 links = make(map[string]int)15 }16 if n.Type == html.ElementNode {17 }18 for c := n.FirstChild; c != nil; c = c.NextSibling {19 links = visit(links, c)20 }21}22import (23func main() {24 doc, err := html.Parse(os.Stdin)25 if err != nil {26 fmt.Fprintf(os.Stderr, "findlinks1: %v27 os.Exit(1)28 }29 for _, link := range visit(nil, doc) {30 fmt.Println(link)31 }32}33func visit(links []string, n *html.Node) []string {34 if n.Type == html.ElementNode && n.Data == "a" {35 for _, a := range n.Attr {36 if a.Key == "href" {37 links = append(links, a.Val)38 }39 }40 }41 for c := n.FirstChild; c != nil; c = c.NextSibling {42 links = visit(links, c)43 }44}45import (46func main() {47 doc, err := html.Parse(os.Stdin)48 if err != nil {49 fmt.Fprintf(os.Stderr, "findlinks1: %v50 os.Exit(1)51 }52 for _, link := range visit(nil, doc, "a", "img") {53 fmt.Println(link)54 }55}56func visit(links []string, n *html.Node, names ...string) []string {
Sizes
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(os.Stdin)4 if err != nil {5 fmt.Fprintf(os.Stderr, "findlinks1: %v\n", err)6 os.Exit(1)7 }8 for k, v := range visit(nil, doc) {9 fmt.Printf("tag %s has %d bytes\n", k, v)10 }11}12func visit(sizes map[string]int, n *html.Node) map[string]int {13 if n.Type == html.ElementNode {14 sizes[n.Data] += n.Size()15 }16 for c := n.FirstChild; c != nil; c = c.NextSibling {17 sizes = visit(sizes, c)18 }19}
Sizes
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(strings.NewReader("<html><head></head><body></body></html>"))4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(doc.FirstChild.Data)8 fmt.Println(doc.FirstChild.FirstChild.Data)9 fmt.Println(doc.FirstChild.FirstChild.NextSibling.Data)10}11import (12func main() {13 doc, err := html.Parse(strings.NewReader("<html><head></head><body></body></html>"))14 if err != nil {15 fmt.Println(err)16 }17 for {18 token := doc.Token()19 fmt.Println(token)20 if token.Type == html.ErrorToken {21 }22 doc.Next()23 }24}25{html 0 0 [] false false}26{head 0 0 [] false false}27{body 0 0 [] false false}28{ErrorToken 0 0 [] false false}29import (30func main() {31 doc, err := html.Parse(strings.NewReader("<html><head></head><body></body></html>"))32 if err != nil {33 fmt.Println(err)34 }35 err = html.Render(os.Stdout, doc)36 if err != nil {37 fmt.Println(err)38 }39}40import (41func main() {42 doc, err := html.Parse(strings.NewReader("<html><head></head><body></body></html>"))43 if err != nil {44 fmt.Println(err)45 }46 _, err = doc.WriteTo(&w)47 if err != nil {48 fmt.Println(err)49 }50 fmt.Println(w.String())51}
Sizes
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(strings.NewReader("<html><head></head><body></body></html>"))4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(doc.Data)8}9import (10func main() {11 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)12 if err != nil {13 fmt.Println(err)14 }15 fmt.Println(doc.Data)16}17import (18func main() {19 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(doc.Data)24}25import (26func main() {27 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println(doc.Data)32}33import (34func main() {35 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)36 if err != nil {37 fmt.Println(err)38 }39 fmt.Println(doc.Data)40}41import (42func main() {43 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)44 if err != nil {45 fmt.Println(err)46 }47 fmt.Println(doc
Sizes
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(strings.NewReader("<html><head></head><body></body></html>"))4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(doc.FirstChild.Data)8}9import (10func main() {11 doc, err := html.Parse(strings.NewReader("<html><head></head><body></body></html>"))12 if err != nil {13 fmt.Println(err)14 }15 fmt.Println(doc.FirstChild.Data)16}17import (18func main() {19 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(doc.FirstChild.Data)24}25import (26func main() {27 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println(doc.FirstChild.Data)32}33import (34func main() {35 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)36 if err != nil {37 fmt.Println(err)38 }39 fmt.Println(doc.FirstChild.Data)40}41import (42func main() {43 doc, err := html.ParseFragment(strings.NewReader("<html><head></head><body></body></html>"), nil)44 if err != nil {45 fmt.Println(err)46 }47 fmt.Println(doc.FirstChild.Data)48}
Sizes
Using AI Code Generation
1import (2func main() {3 file, err := os.Open("index.html")4 if err != nil {5 fmt.Println(err)6 }7 defer file.Close()8 doc, err := html.Parse(file)9 if err != nil {10 fmt.Println(err)11 }12 sizes := make(map[string]int)13 sizes = visit(sizes, doc)14 for k, v := range sizes {15 fmt.Println(k, v)16 }17}18func visit(sizes map[string]int, n *html.Node) map[string]int {19 if n.Type == html.ElementNode {20 }21 for c := n.FirstChild; c != nil; c = c.NextSibling {22 sizes = visit(sizes, c)23 }24}25import (26func main() {27 file, err := os.Open("index.html")28 if err != nil {29 fmt.Println(err)30 }31 defer file.Close()32 doc, err := html.Parse(file)33 if err != nil {34 fmt.Println(err)35 }36 fmt.Println(html.Sizeof(doc))37}38import (39func main() {40 file, err := os.Open("index.html")41 if err != nil {42 fmt.Println(err)43 }44 defer file.Close()45 doc, err := html.Parse(file)46 if err != nil {47 fmt.Println(err)48 }49 fragment, err := html.ParseFragment(file, doc)50 if err != nil {51 fmt.Println(err)52 }53 for _, v := range fragment {54 fmt.Println(v)55 }56}57import (58func main() {59 file, err := os.Open("index.html")60 if err != nil {61 fmt.Println(err)62 }
Sizes
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 defer resp.Body.Close()7 doc, err := html.Parse(resp.Body)8 if err != nil {9 log.Fatal(err)10 }11 fmt.Println("Sizes of the document:")12 fmt.Println("Number of words:", wordCount(doc))13 fmt.Println("Number of images:", imageCount(doc))14 fmt.Println("Number of scripts:", scriptCount(doc))15 fmt.Println("Number of links:", linkCount(doc))16}17func wordCount(doc *html.Node) int {18 var f func(*html.Node)19 f = func(n *html.Node) {20 if n.Type == html.TextNode {21 count += len(n.Data)22 }23 for c := n.FirstChild; c != nil; c = c.NextSibling {24 f(c)25 }26 }27 f(doc)28}29func imageCount(doc *html.Node) int {30 var f func(*html.Node)31 f = func(n *html.Node) {32 if n.Type == html.ElementNode && n.Data == "img" {33 }34 for c := n.FirstChild; c != nil; c = c.NextSibling {35 f(c)36 }37 }38 f(doc)39}40func scriptCount(doc *html.Node) int {41 var f func(*html.Node)42 f = func(n *html.Node) {43 if n.Type == html.ElementNode && n.Data == "script" {44 }45 for c := n.FirstChild; c != nil; c = c.NextSibling {46 f(c)47 }48 }49 f(doc)50}51func linkCount(doc *html.Node) int {52 var f func(*html.Node)53 f = func(n *html.Node) {54 if n.Type == html.ElementNode && n.Data == "a" {55 }56 for c := n.FirstChild; c != nil; c = c.NextSibling {57 f(c)58 }59 }60 f(doc)61}
Sizes
Using AI Code Generation
1import (2func main() {3 doc := html.NewTokenizer(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"))4 fmt.Println(doc.Sizes())5}6import (7func main() {8 doc, err := html.Parse(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"))9 if err != nil {10 fmt.Println(err)11 }12 fmt.Println(doc)13}14import (15func main() {16 doc, err := html.ParseFragment(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"), nil)17 if err != nil {18 fmt.Println(err)19 }20 fmt.Println(doc)21}22import (23func main() {24 doc, err := html.ParseFragment(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"), nil)25 if err != nil {26 fmt.Println(err)27 }28 fmt.Println(doc)29}
Sizes
Using AI Code Generation
1import (2func main() {3 doc, err := html.Parse(os.Stdin)4 if err != nil {5 fmt.Fprintf(os.Stderr, "findlinks1: %v\n", err)6 os.Exit(1)7 }8 fmt.Println(doc.Data)9 fmt.Println(doc.Type)10 fmt.Println(doc.Attr)11}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!