Best Rod code snippet using launcher.Revision
info.go
Source:info.go
...48 // XdgRuntimeDirs returns the XDG_RUNTIME_DIR directories for all users of the snap.49 XdgRuntimeDirs() string50}51// MinimalPlaceInfo returns a PlaceInfo with just the location information for a snap of the given name and revision.52func MinimalPlaceInfo(name string, revision Revision) PlaceInfo {53 return &Info{SideInfo: SideInfo{RealName: name, Revision: revision}}54}55// MountDir returns the base directory where it gets mounted of the snap with the given name and revision.56func MountDir(name string, revision Revision) string {57 return filepath.Join(dirs.SnapMountDir, name, revision.String())58}59// MountFile returns the path where the snap file that is mounted is installed.60func MountFile(name string, revision Revision) string {61 return filepath.Join(dirs.SnapBlobDir, fmt.Sprintf("%s_%s.snap", name, revision))62}63// ScopedSecurityTag returns the snap-specific, scope specific, security tag.64func ScopedSecurityTag(snapName, scopeName, suffix string) string {65 return fmt.Sprintf("snap.%s.%s.%s", snapName, scopeName, suffix)66}67// SecurityTag returns the snap-specific security tag.68func SecurityTag(snapName string) string {69 return fmt.Sprintf("snap.%s", snapName)70}71// AppSecurityTag returns the application-specific security tag.72func AppSecurityTag(snapName, appName string) string {73 return fmt.Sprintf("%s.%s", SecurityTag(snapName), appName)74}75// HookSecurityTag returns the hook-specific security tag.76func HookSecurityTag(snapName, hookName string) string {77 return ScopedSecurityTag(snapName, "hook", hookName)78}79// NoneSecurityTag returns the security tag for interfaces that80// are not associated to an app or hook in the snap.81func NoneSecurityTag(snapName, uniqueName string) string {82 return ScopedSecurityTag(snapName, "none", uniqueName)83}84// SideInfo holds snap metadata that is crucial for the tracking of85// snaps and for the working of the system offline and which is not86// included in snap.yaml or for which the store is the canonical87// source overriding snap.yaml content.88//89// It can be marshalled and will be stored in the system state for90// each currently installed snap revision so it needs to be evolved91// carefully.92//93// Information that can be taken directly from snap.yaml or that comes94// from the store but is not required for working offline should not95// end up in SideInfo.96type SideInfo struct {97 RealName string `yaml:"name,omitempty" json:"name,omitempty"`98 SnapID string `yaml:"snap-id" json:"snap-id"`99 Revision Revision `yaml:"revision" json:"revision"`100 Channel string `yaml:"channel,omitempty" json:"channel,omitempty"`101 EditedSummary string `yaml:"summary,omitempty" json:"summary,omitempty"`102 EditedDescription string `yaml:"description,omitempty" json:"description,omitempty"`103 Private bool `yaml:"private,omitempty" json:"private,omitempty"`104}105// Info provides information about snaps.106type Info struct {107 SuggestedName string108 Version string109 Type Type110 Architectures []string111 Assumes []string112 OriginalSummary string113 OriginalDescription string114 Environment map[string]string115 LicenseAgreement string116 LicenseVersion string117 Epoch string118 Confinement ConfinementType119 Apps map[string]*AppInfo120 Aliases map[string]*AppInfo121 Hooks map[string]*HookInfo122 Plugs map[string]*PlugInfo123 Slots map[string]*SlotInfo124 // The information in all the remaining fields is not sourced from the snap blob itself.125 SideInfo126 // Broken marks if set whether the snap is broken and the reason.127 Broken string128 // The information in these fields is ephemeral, available only from the store.129 DownloadInfo130 IconURL string131 Prices map[string]float64132 MustBuy bool133 PublisherID string134 Publisher string135 Screenshots []ScreenshotInfo136 Channels map[string]*ChannelSnapInfo137}138// ChannelSnapInfo is the minimum information that can be used to clearly139// distinguish different revisions of the same snap.140type ChannelSnapInfo struct {141 Revision Revision `json:"revision"`142 Confinement ConfinementType `json:"confinement"`143 Version string `json:"version"`144 Channel string `json:"channel"`145 Epoch string `json:"epoch"`146 Size int64 `json:"size"`147}148// Name returns the blessed name for the snap.149func (s *Info) Name() string {150 if s.RealName != "" {151 return s.RealName152 }153 return s.SuggestedName154}155// Summary returns the blessed summary for the snap.156func (s *Info) Summary() string {157 if s.EditedSummary != "" {158 return s.EditedSummary159 }160 return s.OriginalSummary161}162// Description returns the blessed description for the snap.163func (s *Info) Description() string {164 if s.EditedDescription != "" {165 return s.EditedDescription166 }167 return s.OriginalDescription168}169// MountDir returns the base directory of the snap where it gets mounted.170func (s *Info) MountDir() string {171 return MountDir(s.Name(), s.Revision)172}173// MountFile returns the path where the snap file that is mounted is installed.174func (s *Info) MountFile() string {175 return MountFile(s.Name(), s.Revision)176}177// HooksDir returns the directory containing the snap's hooks.178func (s *Info) HooksDir() string {179 return filepath.Join(s.MountDir(), "meta", "hooks")180}181// DataDir returns the data directory of the snap.182func (s *Info) DataDir() string {183 return filepath.Join(dirs.SnapDataDir, s.Name(), s.Revision.String())184}185// UserDataDir returns the user-specific data directory of the snap.186func (s *Info) UserDataDir(home string) string {187 return filepath.Join(home, "snap", s.Name(), s.Revision.String())188}189// UserCommonDataDir returns the user-specific data directory common across revision of the snap.190func (s *Info) UserCommonDataDir(home string) string {191 return filepath.Join(home, "snap", s.Name(), "common")192}193// CommonDataDir returns the data directory common across revisions of the snap.194func (s *Info) CommonDataDir() string {195 return filepath.Join(dirs.SnapDataDir, s.Name(), "common")196}197// DataHomeDir returns the per user data directory of the snap.198func (s *Info) DataHomeDir() string {199 return filepath.Join(dirs.SnapDataHomeGlob, s.Name(), s.Revision.String())200}201// CommonDataHomeDir returns the per user data directory common across revisions of the snap.202func (s *Info) CommonDataHomeDir() string {203 return filepath.Join(dirs.SnapDataHomeGlob, s.Name(), "common")204}205// UserXdgRuntimeDir returns the XDG_RUNTIME_DIR directory of the snap for a particular user.206func (s *Info) UserXdgRuntimeDir(euid int) string {207 return filepath.Join("/run/user", fmt.Sprintf("%d/snap.%s", euid, s.Name()))208}209// XdgRuntimeDirs returns the XDG_RUNTIME_DIR directories for all users of the snap.210func (s *Info) XdgRuntimeDirs() string {211 return filepath.Join(dirs.XdgRuntimeDirGlob, fmt.Sprintf("snap.%s", s.Name()))212}213// NeedsDevMode returns whether the snap needs devmode.214func (s *Info) NeedsDevMode() bool {215 return s.Confinement == DevModeConfinement216}217// NeedsClassic returns whether the snap needs classic confinement consent.218func (s *Info) NeedsClassic() bool {219 return s.Confinement == ClassicConfinement220}221// DownloadInfo contains the information to download a snap.222// It can be marshalled.223type DownloadInfo struct {224 AnonDownloadURL string `json:"anon-download-url,omitempty"`225 DownloadURL string `json:"download-url,omitempty"`226 Size int64 `json:"size,omitempty"`227 Sha3_384 string `json:"sha3-384,omitempty"`228 // The server can include information about available deltas for a given229 // snap at a specific revision during refresh. Currently during refresh the230 // server will provide single matching deltas only, from the clients231 // revision to the target revision when available, per requested format.232 Deltas []DeltaInfo `json:"deltas,omitempty"`233}234// DeltaInfo contains the information to download a delta235// from one revision to another.236type DeltaInfo struct {237 FromRevision int `json:"from-revision,omitempty"`238 ToRevision int `json:"to-revision,omitempty"`239 Format string `json:"format,omitempty"`240 AnonDownloadURL string `json:"anon-download-url,omitempty"`241 DownloadURL string `json:"download-url,omitempty"`242 Size int64 `json:"size,omitempty"`243 Sha3_384 string `json:"sha3-384,omitempty"`244}245// sanity check that Info is a PlaceInfo246var _ PlaceInfo = (*Info)(nil)247// PlugInfo provides information about a plug.248type PlugInfo struct {249 Snap *Info250 Name string251 Interface string252 Attrs map[string]interface{}253 Label string254 Apps map[string]*AppInfo255 Hooks map[string]*HookInfo256}257// SecurityTags returns security tags associated with a given plug.258func (plug *PlugInfo) SecurityTags() []string {259 tags := make([]string, 0, len(plug.Apps)+len(plug.Hooks))260 for _, app := range plug.Apps {261 tags = append(tags, app.SecurityTag())262 }263 for _, hook := range plug.Hooks {264 tags = append(tags, hook.SecurityTag())265 }266 sort.Strings(tags)267 return tags268}269// SecurityTags returns security tags associated with a given slot.270func (slot *SlotInfo) SecurityTags() []string {271 tags := make([]string, 0, len(slot.Apps))272 for _, app := range slot.Apps {273 tags = append(tags, app.SecurityTag())274 }275 // NOTE: hooks cannot have slots276 sort.Strings(tags)277 return tags278}279// SlotInfo provides information about a slot.280type SlotInfo struct {281 Snap *Info282 Name string283 Interface string284 Attrs map[string]interface{}285 Label string286 Apps map[string]*AppInfo287}288// AppInfo provides information about a app.289type AppInfo struct {290 Snap *Info291 Name string292 Aliases []string293 Command string294 Daemon string295 StopTimeout timeout.Timeout296 StopCommand string297 ReloadCommand string298 PostStopCommand string299 RestartCond systemd.RestartCondition300 // TODO: this should go away once we have more plumbing and can change301 // things vs refactor302 // https://github.com/snapcore/snapd/pull/794#discussion_r58688496303 BusName string304 Plugs map[string]*PlugInfo305 Slots map[string]*SlotInfo306 Environment map[string]string307}308// ScreenshotInfo provides information about a screenshot.309type ScreenshotInfo struct {310 URL string311 Width int64312 Height int64313}314// HookInfo provides information about a hook.315type HookInfo struct {316 Snap *Info317 Name string318 Plugs map[string]*PlugInfo319}320// SecurityTag returns application-specific security tag.321//322// Security tags are used by various security subsystems as "profile names" and323// sometimes also as a part of the file name.324func (app *AppInfo) SecurityTag() string {325 return AppSecurityTag(app.Snap.Name(), app.Name)326}327// WrapperPath returns the path to wrapper invoking the app binary.328func (app *AppInfo) WrapperPath() string {329 var binName string330 if app.Name == app.Snap.Name() {331 binName = filepath.Base(app.Name)332 } else {333 binName = fmt.Sprintf("%s.%s", app.Snap.Name(), filepath.Base(app.Name))334 }335 return filepath.Join(dirs.SnapBinariesDir, binName)336}337func (app *AppInfo) launcherCommand(command string) string {338 if command != "" {339 command = " " + command340 }341 if app.Name == app.Snap.Name() {342 return fmt.Sprintf("/usr/bin/snap run%s %s", command, app.Name)343 }344 return fmt.Sprintf("/usr/bin/snap run%s %s.%s", command, app.Snap.Name(), filepath.Base(app.Name))345}346// LauncherCommand returns the launcher command line to use when invoking the app binary.347func (app *AppInfo) LauncherCommand() string {348 return app.launcherCommand("")349}350// LauncherStopCommand returns the launcher command line to use when invoking the app stop command binary.351func (app *AppInfo) LauncherStopCommand() string {352 return app.launcherCommand("--command=stop")353}354// LauncherReloadCommand returns the launcher command line to use when invoking the app stop command binary.355func (app *AppInfo) LauncherReloadCommand() string {356 return app.launcherCommand("--command=reload")357}358// LauncherPostStopCommand returns the launcher command line to use when invoking the app post-stop command binary.359func (app *AppInfo) LauncherPostStopCommand() string {360 return app.launcherCommand("--command=post-stop")361}362// ServiceFile returns the systemd service file path for the daemon app.363func (app *AppInfo) ServiceFile() string {364 return filepath.Join(dirs.SnapServicesDir, app.SecurityTag()+".service")365}366// ServiceSocketFile returns the systemd socket file path for the daemon app.367func (app *AppInfo) ServiceSocketFile() string {368 return filepath.Join(dirs.SnapServicesDir, app.SecurityTag()+".socket")369}370func copyEnv(in map[string]string) map[string]string {371 out := make(map[string]string)372 for k, v := range in {373 out[k] = v374 }375 return out376}377// Env returns the app specific environment overrides378func (app *AppInfo) Env() []string {379 env := []string{}380 appEnv := copyEnv(app.Snap.Environment)381 for k, v := range app.Environment {382 appEnv[k] = v383 }384 for k, v := range appEnv {385 env = append(env, fmt.Sprintf("%s=%s\n", k, v))386 }387 return env388}389// SecurityTag returns the hook-specific security tag.390//391// Security tags are used by various security subsystems as "profile names" and392// sometimes also as a part of the file name.393func (hook *HookInfo) SecurityTag() string {394 return HookSecurityTag(hook.Snap.Name(), hook.Name)395}396// Env returns the hook-specific environment overrides397func (hook *HookInfo) Env() []string {398 env := []string{}399 hookEnv := copyEnv(hook.Snap.Environment)400 for k, v := range hookEnv {401 env = append(env, fmt.Sprintf("%s=%s\n", k, v))402 }403 return env404}405func infoFromSnapYamlWithSideInfo(meta []byte, si *SideInfo) (*Info, error) {406 info, err := InfoFromSnapYaml(meta)407 if err != nil {408 return nil, err409 }410 if si != nil {411 info.SideInfo = *si412 }413 return info, nil414}415type NotFoundError struct {416 Snap string417 Revision Revision418}419func (e NotFoundError) Error() string {420 return fmt.Sprintf("cannot find installed snap %q at revision %s", e.Snap, e.Revision)421}422// ReadInfo reads the snap information for the installed snap with the given name and given side-info.423func ReadInfo(name string, si *SideInfo) (*Info, error) {424 snapYamlFn := filepath.Join(MountDir(name, si.Revision), "meta", "snap.yaml")425 meta, err := ioutil.ReadFile(snapYamlFn)426 if os.IsNotExist(err) {427 return nil, &NotFoundError{Snap: name, Revision: si.Revision}428 }429 if err != nil {430 return nil, err431 }432 info, err := infoFromSnapYamlWithSideInfo(meta, si)433 if err != nil {434 return nil, err435 }436 st, err := os.Stat(MountFile(name, si.Revision))437 if err != nil {438 return nil, err439 }440 info.Size = st.Size()441 err = addImplicitHooks(info)442 if err != nil {443 return nil, err444 }445 return info, nil446}447// ReadInfoFromSnapFile reads the snap information from the given File448// and completes it with the given side-info if this is not nil.449func ReadInfoFromSnapFile(snapf Container, si *SideInfo) (*Info, error) {450 meta, err := snapf.ReadFile("meta/snap.yaml")...
launcher_test.go
Source:launcher_test.go
...21)22var setup = got.Setup(nil)23func TestDownloadHosts(t *testing.T) {24 g := setup(t)25 g.Has(launcher.HostGoogle(launcher.RevisionDefault), "https://storage.googleapis.com/chromium-browser-snapshots")26 g.Has(launcher.HostNPM(launcher.RevisionDefault), "https://registry.npmmirror.com/-/binary/chromium-browser-snapshots")27 g.Has(launcher.HostPlaywright(launcher.RevisionDefault), "https://playwright.azureedge.net/")28}29func TestDownload(t *testing.T) {30 g := setup(t)31 s := g.Serve()32 s.Mux.HandleFunc("/fast/", func(rw http.ResponseWriter, r *http.Request) {33 buf := bytes.NewBuffer(nil)34 zw := zip.NewWriter(buf)35 // folder "to"36 h := &zip.FileHeader{Name: "to/"}37 h.SetMode(0755)38 _, err := zw.CreateHeader(h)39 g.E(err)40 // file "file.txt"41 w, err := zw.CreateHeader(&zip.FileHeader{Name: "to/file.txt"})42 g.E(err)43 b := []byte(g.RandStr(2 * 1024 * 1024))44 g.E(w.Write(b))45 g.E(zw.Close())46 rw.Header().Add("Content-Length", fmt.Sprintf("%d", buf.Len()))47 _, _ = io.Copy(rw, buf)48 })49 s.Mux.HandleFunc("/slow/", func(rw http.ResponseWriter, r *http.Request) {50 t := time.NewTimer(3 * time.Second)51 select {52 case <-t.C:53 case <-r.Context().Done():54 t.Stop()55 }56 })57 b, cancel := newBrowser()58 b.Logger = utils.LoggerQuiet59 defer cancel()60 b.Hosts = []launcher.Host{launcher.HostTest(s.URL("/slow")), launcher.HostTest(s.URL("/fast"))}61 b.Dir = filepath.Join("tmp", "browser-from-mirror", g.RandStr(16))62 g.E(b.Download())63 g.Nil(os.Stat(b.Dir))64}65func TestBrowserGet(t *testing.T) {66 g := setup(t)67 g.Nil(os.Stat(launcher.NewBrowser().MustGet()))68 b := launcher.NewBrowser()69 b.Revision = 070 b.Logger = utils.LoggerQuiet71 _, err := b.Get()72 g.Eq(err.Error(), "Can't find a browser binary for your OS, the doc might help https://go-rod.github.io/#/compatibility?id=os")73}74func TestLaunch(t *testing.T) {75 g := setup(t)76 defaults.Proxy = "test.com"77 defer func() { defaults.ResetWith("") }()78 l := launcher.New()79 defer l.Kill()80 u := l.MustLaunch()81 g.Regex(`\Aws://.+\z`, u)82 parsed, _ := url.Parse(u)83 { // test GetWebSocketDebuggerURL84 for _, prefix := range []string{"", ":", "127.0.0.1:", "ws://127.0.0.1:"} {85 u2 := launcher.MustResolveURL(prefix + parsed.Port())86 g.Regex(u, u2)87 }88 _, err := launcher.ResolveURL("")89 g.Err(err)90 }91 {92 _, err := launcher.NewManaged("")93 g.Err(err)94 _, err = launcher.NewManaged("1://")95 g.Err(err)96 _, err = launcher.NewManaged("ws://not-exists")97 g.Err(err)98 }99 {100 g.Panic(func() { launcher.New().Set("a=b") })101 }102}103func TestLaunchUserMode(t *testing.T) {104 g := setup(t)105 l := launcher.NewUserMode()106 defer l.Kill()107 l.Kill() // empty kill should do nothing108 has := l.Has("not-exists")109 g.False(has)110 l.Append("test-append", "a")111 f := l.Get("test-append")112 g.Eq("a", f)113 dir := l.Get(flags.UserDataDir)114 port := 58472115 l = l.Context(g.Context()).Delete("test").Bin("").116 Revision(launcher.RevisionDefault).117 Logger(ioutil.Discard).118 Leakless(false).Leakless(true).119 Headless(false).Headless(true).RemoteDebuggingPort(port).120 NoSandbox(true).NoSandbox(false).121 Devtools(true).Devtools(false).122 StartURL("about:blank").123 Proxy("test.com").124 UserDataDir("test").UserDataDir(dir).125 WorkingDir("").126 Env(append(os.Environ(), "TZ=Asia/Tokyo")...)127 g.Eq(l.FormatArgs(), []string /* len=6 cap=8 */ {128 "--headless",129 `--no-startup-window`, /* len=19 */130 `--proxy-server=test.com`, /* len=23 */131 `--remote-debugging-port=58472`, /* len=29 */132 "--test-append=a",133 "about:blank",134 })135 url := l.MustLaunch()136 g.Eq(url, launcher.NewUserMode().RemoteDebuggingPort(port).MustLaunch())137}138func TestUserModeErr(t *testing.T) {139 g := setup(t)140 _, err := launcher.NewUserMode().RemoteDebuggingPort(48277).Bin("not-exists").Launch()141 g.Err(err)142 _, err = launcher.NewUserMode().RemoteDebuggingPort(58217).Bin("echo").Launch()143 g.Err(err)144}145func TestAppMode(t *testing.T) {146 g := setup(t)147 l := launcher.NewAppMode("http://example.com")148 g.Eq(l.Get(flags.App), "http://example.com")149}150func TestGetWebSocketDebuggerURLErr(t *testing.T) {151 g := setup(t)152 _, err := launcher.ResolveURL("1://")153 g.Err(err)154}155func TestLaunchErr(t *testing.T) {156 g := setup(t)157 g.Panic(func() {158 launcher.New().Bin("not-exists").MustLaunch()159 })160 g.Panic(func() {161 launcher.New().Headless(false).Bin("not-exists").MustLaunch()162 })163 g.Panic(func() {164 launcher.New().ClientHeader()165 })166 {167 l := launcher.New().XVFB()168 _, _ = l.Launch()169 l.Kill()170 }171}172func newBrowser() (*launcher.Browser, func()) {173 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)174 b := launcher.NewBrowser()175 if !testing.Verbose() {176 b.Logger = utils.LoggerQuiet177 }178 b.Context = ctx179 return b, cancel180}181var testProfileDir = flag.Bool("test-profile-dir", false, "set it to test profile dir")182func TestProfileDir(t *testing.T) {183 g := setup(t)184 url := launcher.New().Headless(false).185 ProfileDir("").ProfileDir("test-profile-dir")186 if !*testProfileDir {187 g.Skip("It's not CI friendly, so we skip it!")188 }189 url.MustLaunch()190 userDataDir := url.Get(flags.UserDataDir)191 file, err := os.Stat(filepath.Join(userDataDir, "test-profile-dir"))192 g.E(err)193 g.True(file.IsDir())194}195func TestBrowserExists(t *testing.T) {196 g := setup(t)197 b := launcher.NewBrowser()198 b.Revision = 0199 g.False(b.Exists())200 // fake a broken executable201 g.E(utils.Mkdir(b.Destination()))202 g.Cleanup(func() { _ = os.RemoveAll(b.Destination()) })203 g.False(b.Exists())204}...
Revision
Using AI Code Generation
1import (2func main() {3 auth, err := aws.EnvAuth()4 if err != nil {5 fmt.Println(err)6 }7 client := s3.New(auth, aws.USEast)8 bucket := client.Bucket("mybucket")9 rev, err := bucket.Revision("mykey")10 if err != nil {11 fmt.Println(err)12 }13 fmt.Println(rev)14}
Revision
Using AI Code Generation
1import (2func main() {3 fmt.Println(launcher.Revision())4 z01.PrintRune(launcher.Revision())5}6import (7func main() {8 fmt.Println(launcher.Launcher())9 z01.PrintRune(launcher.Launcher())10}11import (12func main() {13 fmt.Println(launcher.Launch())14 z01.PrintRune(launcher.Launch())15}16import (17func main() {18 fmt.Println(launcher.IsPrime(2))19 z01.PrintRune(launcher.IsPrime(2))20}21import (22func main() {23 launcher.PrintNbrInOrder(123)24 launcher.PrintNbrInOrder(123)25}26import (27func main() {28 table := []int{3, 2, 1}29 launcher.SortIntegerTable(table)30 launcher.SortIntegerTable(table)31}32import (
Revision
Using AI Code Generation
1import "fmt"2type launcher struct {3}4func (l launcher) Revision() {5 fmt.Println("Revision of ", l.name, "is", l.year)6}7func main() {8 l := launcher{"Saturn V", "USA", 1967}9 l.Revision()10}
Revision
Using AI Code Generation
1import "fmt"2import "github.com/rajdeepd/launcher"3func main() {4 fmt.Println(launcher.Revision())5}6import "fmt"7import "github.com/rajdeepd/launcher"8func main() {9 fmt.Println(launcher.Revision())10}
Revision
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println(launcher.Revision())4}5You can't call functions from other packages without importing them. Try this:6import (7func main() {8 fmt.Println(launcher.Revision())9}
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!!