-
Notifications
You must be signed in to change notification settings - Fork 15
fix(analyze): honor offline mode for sharing #18
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ package main | |
|
|
||
| import ( | ||
| "bytes" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
@@ -138,6 +140,91 @@ func TestAnalyze_JSONShape(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestAnalyze_OfflineShareWarnsAndSkipsUpload(t *testing.T) { | ||
|
Member
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. nothing here asserts |
||
| cmd := newRootCmd() | ||
| var out bytes.Buffer | ||
| var errBuf bytes.Buffer | ||
| cmd.SetOut(&out) | ||
| cmd.SetErr(&errBuf) | ||
| cmd.SetArgs([]string{"analyze", "../../testdata/fixtures/basic-chart/values.yaml", "--offline", "--share"}) | ||
| if err := cmd.Execute(); err != nil { | ||
| t.Fatalf("execute --offline --share: %v\nstdout:\n%s\nstderr:\n%s", err, out.String(), errBuf.String()) | ||
| } | ||
| if !strings.Contains(errBuf.String(), "warning: --share is ignored in --offline mode") { | ||
| t.Fatalf("missing offline share warning:\n%s", errBuf.String()) | ||
| } | ||
| if strings.Contains(errBuf.String(), "share URL:") { | ||
| t.Fatalf("offline share should not print share URL:\n%s", errBuf.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestAnalyze_ShareUploadsWhenOfflineDisabled(t *testing.T) { | ||
| shareServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodPost { | ||
| t.Errorf("share upload method = %s, want POST", r.Method) | ||
| } | ||
| if r.Header.Get("X-Optiqor-Hash") == "" { | ||
| t.Error("share upload missing X-Optiqor-Hash header") | ||
| } | ||
| w.WriteHeader(http.StatusNoContent) | ||
| })) | ||
| t.Cleanup(shareServer.Close) | ||
| t.Setenv("OPTIQOR_SHARE_URL", shareServer.URL) | ||
|
|
||
| cmd := newRootCmd() | ||
| var out bytes.Buffer | ||
| var errBuf bytes.Buffer | ||
| cmd.SetOut(&out) | ||
| cmd.SetErr(&errBuf) | ||
| cmd.SetArgs([]string{"analyze", "../../testdata/fixtures/basic-chart/values.yaml", "--share"}) | ||
| if err := cmd.Execute(); err != nil { | ||
| t.Fatalf("execute --share: %v\nstdout:\n%s\nstderr:\n%s", err, out.String(), errBuf.String()) | ||
| } | ||
| if strings.Contains(errBuf.String(), "warning: --share is ignored in --offline mode") { | ||
| t.Fatalf("online share should not warn about offline mode:\n%s", errBuf.String()) | ||
| } | ||
| if !strings.Contains(errBuf.String(), "share URL:") { | ||
| t.Fatalf("online share should print share URL:\n%s", errBuf.String()) | ||
| } | ||
| if !strings.Contains(errBuf.String(), "(uploaded)") { | ||
| t.Fatalf("online share should report upload success:\n%s", errBuf.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestAnalyze_OfflineEnvShareWarnsAndSkipsUpload(t *testing.T) { | ||
|
Member
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. right now nothing proves env beats an explicit |
||
| t.Setenv("OPTIQOR_OFFLINE", "1") | ||
| cmd := newRootCmd() | ||
| var out bytes.Buffer | ||
| var errBuf bytes.Buffer | ||
| cmd.SetOut(&out) | ||
| cmd.SetErr(&errBuf) | ||
| cmd.SetArgs([]string{"analyze", "../../testdata/fixtures/basic-chart/values.yaml", "--offline=false", "--share"}) | ||
| if err := cmd.Execute(); err != nil { | ||
| t.Fatalf("execute OPTIQOR_OFFLINE=1 --offline=false --share: %v\nstdout:\n%s\nstderr:\n%s", err, out.String(), errBuf.String()) | ||
| } | ||
| if !strings.Contains(errBuf.String(), "warning: --share is ignored in --offline mode") { | ||
| t.Fatalf("missing env offline share warning:\n%s", errBuf.String()) | ||
| } | ||
| if strings.Contains(errBuf.String(), "share URL:") { | ||
| t.Fatalf("offline env share should not print share URL:\n%s", errBuf.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestAnalyze_HelpDocumentsOfflineEnv(t *testing.T) { | ||
| cmd := newRootCmd() | ||
| var buf bytes.Buffer | ||
| cmd.SetOut(&buf) | ||
| cmd.SetArgs([]string{"analyze", "--help"}) | ||
| if err := cmd.Execute(); err != nil { | ||
| t.Fatalf("execute analyze --help: %v", err) | ||
| } | ||
| for _, want := range []string{"--offline", "OPTIQOR_OFFLINE=1", "--share"} { | ||
| if !strings.Contains(buf.String(), want) { | ||
| t.Errorf("analyze help missing %q:\n%s", want, buf.String()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestResolveColor_NoColorFlag(t *testing.T) { | ||
| cmd := newRootCmd() | ||
| if got := resolveColor(cmd, true); got { | ||
|
|
||
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.
worth a doc line saying this is the canonical egress gate. when
watchor realauditadd network calls they need to consult this too.