-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: MsgPolicyCmd -> MsgSignedPolicyCmd
- Loading branch information
Showing
36 changed files
with
902 additions
and
1,977 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
|
||
test "github.com/sourcenetwork/sourcehub/tests/integration/acp" | ||
"github.com/sourcenetwork/sourcehub/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "test_env_generator {permutation}", | ||
Short: "test_env_generator permutates through SourceHub's test suite environment variables", | ||
Long: ` | ||
test_env_generator outputs the set of environment variables which should be set for each test permutation. | ||
With no input, prints the amount of permutations available. | ||
Permutation numbering is 0 based (eg if there are permutations the allowed options arguments are 0, 1, 2) | ||
`, | ||
Args: cobra.MaximumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
environs := genEnvirons() | ||
|
||
if len(args) == 0 { | ||
fmt.Printf("%v\n", len(environs)) | ||
return | ||
} | ||
|
||
if args[0] == "all" { | ||
for _, env := range environs { | ||
fmt.Println(env) | ||
} | ||
return | ||
} | ||
|
||
index, err := strconv.Atoi(args[0]) | ||
if err != nil { | ||
log.Fatalf("%v is an invalid index", args[0]) | ||
} | ||
if index < 0 || index > len(environs) { | ||
log.Fatalf("index must be within [0, %v]", len(environs)-1) | ||
} | ||
|
||
println(environs[index]) | ||
}, | ||
} | ||
|
||
func main() { | ||
rootCmd.Execute() | ||
} | ||
|
||
func writeKV(builder *strings.Builder, key, value string) { | ||
builder.WriteString("export ") | ||
builder.WriteString(key) | ||
builder.WriteRune('=') | ||
builder.WriteRune('"') | ||
builder.WriteString(value) | ||
builder.WriteRune('"') | ||
builder.WriteRune(' ') | ||
builder.WriteRune(';') | ||
} | ||
|
||
func genEnvirons() []string { | ||
combinations := len(test.ActorKeyMap) * len(test.ExecutorStrategyMap) * len(test.AuthenticationStrategyMap) | ||
environs := make([]string, 0, combinations) | ||
|
||
for actorKeyVar := range test.ActorKeyMap { | ||
for executorVar := range test.ExecutorStrategyMap { | ||
for authStratVar := range test.AuthenticationStrategyMap { | ||
builder := strings.Builder{} | ||
writeKV(&builder, test.SourceHubActorEnvVar, actorKeyVar) | ||
writeKV(&builder, test.SourceHubExecutorEnvVar, executorVar) | ||
writeKV(&builder, test.SourceHubAuthStratEnvVar, authStratVar) | ||
environ := builder.String() | ||
environs = append(environs, environ) | ||
} | ||
} | ||
} | ||
|
||
utils.SortSlice(environs) | ||
|
||
return environs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.