11/*
22MIT License
33
4- Copyright (c) 2023 Rick
4+ Copyright (c) 2023-2024 Rick
55
66Permission is hereby granted, free of charge, to any person obtaining a copy
77of this software and associated documentation files (the "Software"), to deal
@@ -40,34 +40,35 @@ type FakeExecer struct {
4040 ExpectOS string
4141 ExpectArch string
4242 ExpectLookPath string
43+ Env map [string ]string
4344}
4445
45- func (f FakeExecer ) WithContext (ctx context.Context ) Execer {
46+ func (f * FakeExecer ) WithContext (ctx context.Context ) Execer {
4647 return f
4748}
4849
4950// LookPath is a fake method
50- func (f FakeExecer ) LookPath (path string ) (string , error ) {
51+ func (f * FakeExecer ) LookPath (path string ) (string , error ) {
5152 return f .ExpectLookPath , f .ExpectLookPathError
5253}
5354
5455// Command is a fake method
55- func (f FakeExecer ) Command (name string , arg ... string ) ([]byte , error ) {
56+ func (f * FakeExecer ) Command (name string , arg ... string ) ([]byte , error ) {
5657 return []byte (f .ExpectOutput ), f .ExpectError
5758}
5859
5960// RunCommand runs a command
60- func (f FakeExecer ) RunCommand (name string , arg ... string ) error {
61+ func (f * FakeExecer ) RunCommand (name string , arg ... string ) error {
6162 return f .ExpectError
6263}
6364
6465// RunCommandInDir is a fake method
65- func (f FakeExecer ) RunCommandInDir (name , dir string , args ... string ) error {
66+ func (f * FakeExecer ) RunCommandInDir (name , dir string , args ... string ) error {
6667 return f .ExpectError
6768}
6869
6970// RunCommandAndReturn is a fake method
70- func (f FakeExecer ) RunCommandAndReturn (name , dir string , args ... string ) (result string , err error ) {
71+ func (f * FakeExecer ) RunCommandAndReturn (name , dir string , args ... string ) (result string , err error ) {
7172 if err = f .ExpectError ; err == nil {
7273 result = f .ExpectOutput
7374 } else {
@@ -78,41 +79,57 @@ func (f FakeExecer) RunCommandAndReturn(name, dir string, args ...string) (resul
7879}
7980
8081// RunCommandWithSudo is a fake method
81- func (f FakeExecer ) RunCommandWithSudo (name string , args ... string ) (err error ) {
82+ func (f * FakeExecer ) RunCommandWithSudo (name string , args ... string ) (err error ) {
8283 return f .ExpectError
8384}
8485
8586// RunCommandWithBuffer is a fake method
86- func (f FakeExecer ) RunCommandWithBuffer (name , dir string , stdout , stderr * bytes.Buffer , args ... string ) error {
87+ func (f * FakeExecer ) RunCommandWithBuffer (name , dir string , stdout , stderr * bytes.Buffer , args ... string ) error {
8788 return f .ExpectError
8889}
8990
9091// RunCommandWithIO is a fake method
91- func (f FakeExecer ) RunCommandWithIO (name , dir string , stdout , stderr io.Writer , p chan Process , args ... string ) error {
92+ func (f * FakeExecer ) RunCommandWithIO (name , dir string , stdout , stderr io.Writer , p chan Process , args ... string ) error {
9293 return f .ExpectError
9394}
9495
9596// RunCommandWithEnv is a fake method
96- func (f FakeExecer ) RunCommandWithEnv (name string , argv , envv []string , stdout , stderr io.Writer ) error {
97+ func (f * FakeExecer ) RunCommandWithEnv (name string , argv , envv []string , stdout , stderr io.Writer ) error {
9798 return f .ExpectError
9899}
99100
100101// SystemCall is a fake method
101- func (f FakeExecer ) SystemCall (name string , argv []string , envv []string ) error {
102+ func (f * FakeExecer ) SystemCall (name string , argv []string , envv []string ) error {
102103 return f .ExpectError
103104}
104105
105106// MkdirAll is the wrapper of os.MkdirAll
106- func (f FakeExecer ) MkdirAll (path string , perm os.FileMode ) error {
107+ func (f * FakeExecer ) MkdirAll (path string , perm os.FileMode ) error {
107108 return f .ExpectError
108109}
109110
110111// OS returns the os name
111- func (f FakeExecer ) OS () string {
112+ func (f * FakeExecer ) OS () string {
112113 return f .ExpectOS
113114}
114115
115116// Arch returns the os arch
116- func (f FakeExecer ) Arch () string {
117+ func (f * FakeExecer ) Arch () string {
117118 return f .ExpectArch
118119}
120+
121+ // Getenv returns the env value by key
122+ func (f * FakeExecer ) Getenv (key string ) string {
123+ return f .Env [key ]
124+ }
125+
126+ // Setenv sets the key-value pair into the env
127+ func (f * FakeExecer ) Setenv (key , value string ) error {
128+ if f .Env == nil {
129+ f .Env = make (map [string ]string )
130+ }
131+ f .Env [key ] = value
132+ return nil
133+ }
134+
135+ var _ Execer = & FakeExecer {}
0 commit comments