glu script: sudo and testability

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

glu script: sudo and testability

sgillespie
I understand I can easily use sudo in a glu script.  However, I don't have sudo access on my development machines, which means I can't create a unit/integration test for this.  How would you approach this problem?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glu script: sudo and testability

frenchyan
Administrator
One way you could go about it is having an init parameter to use sudo or not in your model. So in the glu script you could do:

if(params.useSudo)
  // invoke command with sudo
else
  // invoke command without sudo

Another way would be to determine your environment in the glu script (shell.env), or any other (unix) environment property

Another way would be to try to execute sudo and if it does not work then don't use it:

private void canUseSudo()
{
  try
  {
    shell.exec(command: "sudo pwd")
    return true
  }
  catch(xxx)
  {
     return false;
  }
}

The problem with this last method is that if you must use sudo and a machine in prod is misconfigured it won't use it...

Yan

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glu script: sudo and testability

sgillespie
The first option seems like it would work well. Thanks for responding
Loading...