Skip to content

Commit

Permalink
style: Added a log when going the legacy path
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFaucherre authored and elliotforbes committed Apr 20, 2023
1 parent d400517 commit 7d09d97
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (c *ConfigCompiler) ConfigQuery(
configCompilationResp := &ConfigResponse{}
statusCode, originalErr := c.compileRestClient.DoRequest(req, configCompilationResp)
if statusCode == 404 {
fmt.Fprintf(os.Stderr, "You are using a old version of CircleCI Server, please consider updating")
legacyResponse, err := c.legacyConfigQueryByOrgID(configString, orgID, params, values, c.cfg)
if err != nil {
return nil, err
Expand Down
37 changes: 36 additions & 1 deletion config/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,41 @@ func TestLegacyFlow(t *testing.T) {
})
_, err := compiler.ConfigQuery("testdata/config.yml", "1234", Parameters{}, Values{})
assert.Error(t, err)
assert.Contains(t, "failed to validate", err.Error())
assert.Contains(t, err.Error(), "failed to validate")
})

t.Run("tests that the compiler fails out completely when a non-404 is returned from the http endpoint", func(t *testing.T) {
mux := http.NewServeMux()
gqlHitCounter := 0

mux.HandleFunc("/compile-config-with-defaults", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)

})

mux.HandleFunc("/me/collaborations", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `[{"vcs_type":"circleci","slug":"gh/test","id":"2345"}]`)
})

mux.HandleFunc("/graphql-unstable", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"data":{"buildConfig":{"errors":[{"message": "failed to validate"}]}}}`)
gqlHitCounter++
})

svr := httptest.NewServer(mux)
defer svr.Close()

compiler := New(&settings.Config{
Host: svr.URL,
Endpoint: "/graphql-unstable",
HTTPClient: http.DefaultClient,
Token: "",
})
_, err := compiler.ConfigQuery("testdata/config.yml", "1234", Parameters{}, Values{})
assert.Error(t, err)
assert.Contains(t, err.Error(), "config compilation request returned an error:")
assert.Equal(t, 0, gqlHitCounter)
})
}

0 comments on commit 7d09d97

Please sign in to comment.