github.com/sathish1597/hashicorp-terraform@v0.11.12-beta1/svchost/auth/test-helper/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 // This is a simple program that implements the "helper program" protocol 9 // for the svchost/auth package for unit testing purposes. 10 11 func main() { 12 args := os.Args 13 14 if len(args) < 3 { 15 die("not enough arguments\n") 16 } 17 18 if args[1] != "get" { 19 die("unknown subcommand %q\n", args[1]) 20 } 21 22 host := args[2] 23 24 switch host { 25 case "example.com": 26 fmt.Print(`{"token":"example-token"}`) 27 case "other-cred-type.example.com": 28 fmt.Print(`{"username":"alfred"}`) // unrecognized by main program 29 case "fail.example.com": 30 die("failing because you told me to fail\n") 31 default: 32 fmt.Print("{}") // no credentials available 33 } 34 } 35 36 func die(f string, args ...interface{}) { 37 fmt.Fprintf(os.Stderr, fmt.Sprintf(f, args...)) 38 os.Exit(1) 39 }