github.com/blend/go-sdk@v1.20220411.3/oauth/config_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package oauth 9 10 import ( 11 "context" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 "github.com/blend/go-sdk/configutil" 16 "github.com/blend/go-sdk/env" 17 ) 18 19 var ( 20 _ configutil.Resolver = (*Config)(nil) 21 ) 22 23 func TestNewConfigFromEnv(t *testing.T) { 24 assert := assert.New(t) 25 defer env.Restore() 26 27 env.Env().Set("OAUTH_REDIRECT_URI", "https://app.com/oauth/google") 28 env.Env().Set("OAUTH_HOSTED_DOMAIN", "foo.com") 29 env.Env().Set("OAUTH_CLIENT_ID", "foo") 30 env.Env().Set("OAUTH_CLIENT_SECRET", "bar") 31 32 cfg := &Config{} 33 ctx := env.WithVars(context.Background(), env.Env()) 34 assert.Nil(cfg.Resolve(ctx)) 35 assert.Equal("foo", cfg.ClientID) 36 assert.Equal("bar", cfg.ClientSecret) 37 assert.Equal("https://app.com/oauth/google", cfg.RedirectURI) 38 assert.Equal("foo.com", cfg.HostedDomain) 39 } 40 41 func TestConfig(t *testing.T) { 42 assert := assert.New(t) 43 44 assert.True(Config{}.IsZero()) 45 assert.True(Config{ClientID: "foo"}.IsZero()) 46 assert.False(Config{ClientID: "foo", ClientSecret: "bar"}.IsZero()) 47 }