(t *testing.T)
| 29 | } |
| 30 | |
| 31 | func TestNewToken(t *testing.T) { |
| 32 | viper.Set("spotify.callback_url", "http://localhost:8732/callback") |
| 33 | viper.Set("spotify.client_id", "client_id") |
| 34 | viper.Set("spotify.client_secret", "client_secret") |
| 35 | |
| 36 | ms := new(mocks.DiskplayerServer) |
| 37 | |
| 38 | s := &http.Server{} |
| 39 | |
| 40 | a, err := NewAuthenticator() |
| 41 | assert.NoError(t, err) |
| 42 | |
| 43 | ch := make(chan *oauth2.Token, 1) |
| 44 | ms.On("TokenChannel").Return(ch) |
| 45 | ms.On("Authenticator").Return(a, nil) |
| 46 | ms.On("RunCallbackServer").Return(s, nil) |
| 47 | |
| 48 | var wg sync.WaitGroup |
| 49 | wg.Add(1) |
| 50 | |
| 51 | tokExpected := oauth2.Token{ |
| 52 | AccessToken: "temp_access_token", |
| 53 | TokenType: "Bearer", |
| 54 | RefreshToken: "temp_refresh_token", |
| 55 | Expiry: time.Time{}, |
| 56 | } |
| 57 | |
| 58 | go func(wg *sync.WaitGroup) { |
| 59 | defer wg.Done() |
| 60 | tokActual, e := NewToken(ms) |
| 61 | assert.NoError(t, e) |
| 62 | assert.Equal(t, tokActual.TokenType, tokExpected.TokenType) |
| 63 | assert.Equal(t, tokActual.AccessToken, tokExpected.AccessToken) |
| 64 | assert.Equal(t, tokActual.RefreshToken, tokExpected.RefreshToken) |
| 65 | assert.Equal(t, tokActual.Expiry, tokExpected.Expiry) |
| 66 | }(&wg) |
| 67 | |
| 68 | ch <- &tokExpected |
| 69 | wg.Wait() |
| 70 | } |
| 71 | |
| 72 | func TestNewTokenCallbackServerError(t *testing.T) { |
| 73 | viper.Set("spotify.callback_url", "http://localhost:8732/callback") |
nothing calls this directly
no test coverage detected