MCPcopy Create free account
hub / github.com/cli/cli / validateFixtureRepositoryDeclaration

Function validateFixtureRepositoryDeclaration

acceptance/user_capability_test.go:84–129  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

82}
83
84func validateFixtureRepositoryDeclaration(file string) error {
85 f, err := os.Open(file)
86 if err != nil {
87 return err
88 }
89 defer f.Close()
90
91 var declarations [][]string
92 hasDirectRepositoryCreation := false
93 scanner := bufio.NewScanner(f)
94 for scanner.Scan() {
95 line := strings.TrimSuffix(scanner.Text(), "\r")
96 if strings.HasPrefix(line, "-- ") && strings.HasSuffix(line, " --") {
97 break
98 }
99 if strings.HasPrefix(line, "fixture-repo ") {
100 declarations = append(declarations, strings.Fields(line))
101 }
102 if directRepositoryCreation.MatchString(line) {
103 hasDirectRepositoryCreation = true
104 }
105 }
106 if err := scanner.Err(); err != nil {
107 return err
108 }
109
110 if len(declarations) != 1 {
111 return fmt.Errorf("%s: script must contain exactly one fixture-repo declaration; %s", file, fixtureRepositoryDeclarationHelp)
112 }
113
114 declaration := declarations[0]
115 switch {
116 case len(declaration) == 2 && declaration[1] == "none":
117 return nil
118 case len(declaration) == 3 && (declaration[1] == "shared" || declaration[1] == "isolated"):
119 if !fixtureRepositoryEnvironmentVariable.MatchString(declaration[2]) {
120 return fmt.Errorf("%s: fixture repository environment variable must match %s; for example:\n fixture-repo shared REPO", file, fixtureRepositoryEnvironmentVariable)
121 }
122 if hasDirectRepositoryCreation {
123 return fmt.Errorf("%s: scripts using a managed fixture repository must not run gh repo create; either remove gh repo create or use:\n fixture-repo none", file)
124 }
125 return nil
126 default:
127 return fmt.Errorf("%s: invalid fixture-repo declaration; %s", file, fixtureRepositoryDeclarationHelp)
128 }
129}
130
131func TestTokenHasUserCapability(t *testing.T) {
132 tests := []struct {

Calls 5

OpenMethod · 0.80
ErrMethod · 0.80
CloseMethod · 0.65
FieldsMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected