File: test_gcp_command_credentials.rb

package info (click to toggle)
ruby-kubeclient 4.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,112 kB
  • sloc: ruby: 4,225; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 868 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require_relative 'test_helper'
require 'open3'

# Unit tests for the GCPCommandCredentials token provider
class GCPCommandCredentialsTest < Minitest::Test
  def test_token
    opts = { 'cmd-args' => 'config config-helper --format=json',
             'cmd-path' => '/path/to/gcloud',
             'expiry-key' => '{.credential.token_expiry}',
             'token-key' => '{.credential.access_token}' }

    creds = JSON.dump(
      'credential' => {
        'access_token' => '9A3A941836F2458175BE18AA1971EBBF47949B07',
        'token_expiry' => '2019-04-12T15:02:51Z'
      }
    )

    st = Minitest::Mock.new
    st.expect(:success?, true)

    Open3.stub(:capture3, [creds, nil, st]) do
      assert_equal('9A3A941836F2458175BE18AA1971EBBF47949B07',
                   Kubeclient::GCPCommandCredentials.token(opts))
    end
  end
end