Skip to content

Commit 7d1a115

Browse files
author
Katrina Owen
committed
Add guard for missing API URL in download command
1 parent f80a8bd commit 7d1a115

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

cmd/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func runDownload(cfg config.Configuration, flags *pflag.FlagSet, args []string)
5252
tokenURL := config.InferSiteURL(usrCfg.GetString("apibaseurl")) + "/my/settings"
5353
return fmt.Errorf(msgWelcomePleaseConfigure, tokenURL, BinaryName)
5454
}
55-
if usrCfg.GetString("workspace") == "" {
55+
if usrCfg.GetString("workspace") == "" || usrCfg.GetString("apibaseurl") == "" {
5656
return fmt.Errorf(msgRerunConfigure, BinaryName)
5757
}
5858

cmd/download_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,25 @@ func TestDownloadWithoutWorkspace(t *testing.T) {
3939
}
4040
}
4141

42+
func TestDownloadWithoutBaseURL(t *testing.T) {
43+
v := viper.New()
44+
v.Set("token", "abc123")
45+
v.Set("workspace", "/home/whatever")
46+
cfg := config.Configuration{
47+
UserViperConfig: v,
48+
}
49+
50+
err := runDownload(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{})
51+
if assert.Error(t, err) {
52+
assert.Regexp(t, "re-run the configure", err.Error())
53+
}
54+
}
55+
4256
func TestDownloadWithoutFlags(t *testing.T) {
4357
v := viper.New()
4458
v.Set("token", "abc123")
4559
v.Set("workspace", "/home/username")
60+
v.Set("apibaseurl", "http://example.com")
4661

4762
cfg := config.Configuration{
4863
UserViperConfig: v,

0 commit comments

Comments
 (0)