@@ -41,32 +41,48 @@ func TestLoadBuildsSpecURLFromWherobotsAPIURL(t *testing.T) {
4141 }
4242}
4343
44- func TestLoadRequiresWherobotsAPIKey (t * testing.T ) {
44+ func TestLoadSucceedsWithoutAPIKey (t * testing.T ) {
4545 t .Setenv ("WHEROBOTS_API_URL" , "" )
4646 t .Setenv ("WHEROBOTS_API_KEY" , "" )
4747
48- _ , err := Load ()
48+ cfg , err := Load ()
49+ if err != nil {
50+ t .Fatalf ("Load() error = %v" , err )
51+ }
52+ if cfg .APIKey != "" {
53+ t .Fatalf ("APIKey = %q, want empty" , cfg .APIKey )
54+ }
55+ }
56+
57+ func TestRequireAPIKeyErrorsWithDefaultURL (t * testing.T ) {
58+ cfg := Config {OpenAPIURL : "https://api.cloud.wherobots.com/openapi.json" }
59+ err := cfg .RequireAPIKey ()
4960 if err == nil {
50- t .Fatalf ("expected Load() error" )
61+ t .Fatalf ("expected error" )
5162 }
5263 if ! strings .Contains (err .Error (), "https://cloud.wherobots.com/settings#api-keys" ) {
5364 t .Fatalf ("error should contain default API key URL, got: %v" , err )
5465 }
5566}
5667
57- func TestLoadMissingKeyUsesCustomAPIHost (t * testing.T ) {
58- t .Setenv ("WHEROBOTS_API_URL" , "https://api.staging.wherobots.com" )
59- t .Setenv ("WHEROBOTS_API_KEY" , "" )
60-
61- _ , err := Load ()
68+ func TestRequireAPIKeyErrorsWithCustomURL (t * testing.T ) {
69+ cfg := Config {OpenAPIURL : "https://api.staging.wherobots.com/openapi.json" }
70+ err := cfg .RequireAPIKey ()
6271 if err == nil {
63- t .Fatalf ("expected Load() error" )
72+ t .Fatalf ("expected error" )
6473 }
6574 if ! strings .Contains (err .Error (), "https://staging.wherobots.com/settings#api-keys" ) {
6675 t .Fatalf ("error should contain custom API key URL, got: %v" , err )
6776 }
6877}
6978
79+ func TestRequireAPIKeySucceedsWithKey (t * testing.T ) {
80+ cfg := Config {APIKey : "key-1" }
81+ if err := cfg .RequireAPIKey (); err != nil {
82+ t .Fatalf ("unexpected error: %v" , err )
83+ }
84+ }
85+
7086func TestLoadReadsUploadPathConfig (t * testing.T ) {
7187 t .Setenv ("WHEROBOTS_API_URL" , "" )
7288 t .Setenv ("WHEROBOTS_API_KEY" , "key-1" )
0 commit comments