-
Notifications
You must be signed in to change notification settings - Fork 69
Deprecate -endpoint flag #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4cfa74e
Deprecate -endpoint flag
ryanslade b269aee
Update changelog.
ryanslade 1459018
Update cmd/src/main.go
ryanslade 83f9013
Clean up CHANGELOG
ryanslade 68e2bef
Use t.Cleanup
ryanslade 0584190
Use Go 1.14
ryanslade e52af5f
Use Go 1.14 in Travis too
ryanslade bcea809
Try specific version of Go for Appveyor
ryanslade 5f86ece
Try example appveyor.yml
ryanslade ef27818
Revert "Try example appveyor.yml"
ryanslade b794310
One more attempt, use different GOPATH
ryanslade 8a6f691
Revert back to being Go 1.13 compatible
ryanslade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,179 @@ | ||||||||||||||||||||||||||||||||||||||||||
| package main | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||
| "encoding/json" | ||||||||||||||||||||||||||||||||||||||||||
| "io/ioutil" | ||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| "github.com/google/go-cmp/cmp" | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func TestReadConfig(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||
| makeTempConfig := func(t *testing.T, c config) (string, func()) { | ||||||||||||||||||||||||||||||||||||||||||
| data, err := json.Marshal(c) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| tmpDir, err := ioutil.TempDir("", "") | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| filePath := filepath.Join(tmpDir, "config.json") | ||||||||||||||||||||||||||||||||||||||||||
| err = ioutil.WriteFile(filePath, data, 0600) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return filePath, func() { os.RemoveAll(tmpDir) } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| tests := []struct { | ||||||||||||||||||||||||||||||||||||||||||
| name string | ||||||||||||||||||||||||||||||||||||||||||
| fileContents *config | ||||||||||||||||||||||||||||||||||||||||||
| envToken string | ||||||||||||||||||||||||||||||||||||||||||
| envEndpoint string | ||||||||||||||||||||||||||||||||||||||||||
| flagEndpoint string | ||||||||||||||||||||||||||||||||||||||||||
| want *config | ||||||||||||||||||||||||||||||||||||||||||
| wantErr string | ||||||||||||||||||||||||||||||||||||||||||
| }{ | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "defaults", | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://sourcegraph.com", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "config file, no overrides, trim slash", | ||||||||||||||||||||||||||||||||||||||||||
| fileContents: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com/", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "deadbeef", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "deadbeef", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "config file, token override only", | ||||||||||||||||||||||||||||||||||||||||||
| fileContents: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com/", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "deadbeef", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| envToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| want: nil, | ||||||||||||||||||||||||||||||||||||||||||
| wantErr: errConfigMerge.Error(), | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "config file, endpoint override only", | ||||||||||||||||||||||||||||||||||||||||||
| fileContents: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com/", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "deadbeef", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| envEndpoint: "https://exmaple2.com", | ||||||||||||||||||||||||||||||||||||||||||
| want: nil, | ||||||||||||||||||||||||||||||||||||||||||
| wantErr: errConfigMerge.Error(), | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "config file, both override", | ||||||||||||||||||||||||||||||||||||||||||
| fileContents: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com/", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "deadbeef", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| envToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| envEndpoint: "https://override.com", | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://override.com", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "no config file, token from environment", | ||||||||||||||||||||||||||||||||||||||||||
| envToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://sourcegraph.com", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "no config file, endpoint from environment", | ||||||||||||||||||||||||||||||||||||||||||
| envEndpoint: "https://example.com", | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "no config file, both variables", | ||||||||||||||||||||||||||||||||||||||||||
| envEndpoint: "https://example.com", | ||||||||||||||||||||||||||||||||||||||||||
| envToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "endpoint flag should override config", | ||||||||||||||||||||||||||||||||||||||||||
| flagEndpoint: "https://override.com/", | ||||||||||||||||||||||||||||||||||||||||||
| fileContents: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://example.com/", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "deadbeef", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://override.com", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "deadbeef", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| name: "endpoint flag should override environment", | ||||||||||||||||||||||||||||||||||||||||||
| flagEndpoint: "https://override.com/", | ||||||||||||||||||||||||||||||||||||||||||
| envEndpoint: "https://example.com", | ||||||||||||||||||||||||||||||||||||||||||
| envToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| want: &config{ | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint: "https://override.com", | ||||||||||||||||||||||||||||||||||||||||||
| AccessToken: "abc", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| for _, test := range tests { | ||||||||||||||||||||||||||||||||||||||||||
| t.Run(test.name, func(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||
| oldConfigPath := *configPath | ||||||||||||||||||||||||||||||||||||||||||
| defer func() { *configPath = oldConfigPath }() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if test.flagEndpoint != "" { | ||||||||||||||||||||||||||||||||||||||||||
| val := test.flagEndpoint | ||||||||||||||||||||||||||||||||||||||||||
| endpoint = &val | ||||||||||||||||||||||||||||||||||||||||||
| defer func() { endpoint = nil }() | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if test.fileContents != nil { | ||||||||||||||||||||||||||||||||||||||||||
| p, cleanup := makeTempConfig(t, *test.fileContents) | ||||||||||||||||||||||||||||||||||||||||||
| defer cleanup() | ||||||||||||||||||||||||||||||||||||||||||
| *configPath = p | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| oldToken := os.Getenv("SRC_ACCESS_TOKEN") | ||||||||||||||||||||||||||||||||||||||||||
| defer func() { os.Setenv("SRC_ACCESS_TOKEN", oldToken) }() | ||||||||||||||||||||||||||||||||||||||||||
| oldEndpoint := os.Getenv("SRC_ENDPOINT") | ||||||||||||||||||||||||||||||||||||||||||
| defer func() { os.Setenv("SRC_ENDPOINT", oldEndpoint) }() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if err := os.Setenv("SRC_ACCESS_TOKEN", test.envToken); err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if err := os.Setenv("SRC_ENDPOINT", test.envEndpoint); err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+155
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a bit easier to parse visually and read 😄 But, I was in the mood to write a tiny function just now, feel free to ignore:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| config, err := readConfig() | ||||||||||||||||||||||||||||||||||||||||||
| if diff := cmp.Diff(test.want, config); diff != "" { | ||||||||||||||||||||||||||||||||||||||||||
| t.Errorf("config: %v", diff) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| var errMsg string | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| errMsg = err.Error() | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if diff := cmp.Diff(test.wantErr, errMsg); diff != "" { | ||||||||||||||||||||||||||||||||||||||||||
| t.Errorf("err: %v", diff) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you already have
tat hand, you could do this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
t.Cleanuporiginally butsrc-cliis using an older version of Go in the build pipeline.Let me check how easy it is to update that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments and commits, I couldn't get Appveyor to use Go 1.14