1+ # frozen_string_literal: true
2+
3+ require 'spec_helper'
4+
5+ describe Travis ::Vcs ::Perforce ::Clone , :sexp do
6+ let ( :data ) { payload_for ( payload_name , :ruby , config : { } ) }
7+ let ( :sh ) { Travis ::Shell ::Builder . new }
8+ let ( :clone ) { described_class . new ( sh , Travis ::Build ::Data . new ( data ) ) }
9+
10+ describe '#apply' do
11+ let ( :payload_name ) { :perforce }
12+ let ( :key_sexp ) { [ :cmd , "echo $(p4 info | grep 'Server address:' | cut -d ' ' -f 3- 2>/dev/null)=pubkey:privatekey > /tmp/p4ticket" ] }
13+ let ( :tickets_sexp ) { [ :export , [ 'P4TICKETS' , '/tmp/p4ticket' ] ] }
14+ let ( :client_sexp ) { [ :cmd , 'p4 -v ssl.client.trust.name=1 client -S //depot/main -o | p4 -v ssl.client.trust.name=1 client -i' ] }
15+
16+ subject { sh . to_sexp }
17+
18+ before { clone . apply }
19+
20+ it { is_expected . to include_sexp ( [ :export , [ 'P4USER' , 'pubkey' ] , echo : true ] ) }
21+ it { is_expected . to include_sexp ( [ :export , [ 'P4CHARSET' , 'utf8' ] ] ) }
22+ it { is_expected . to include_sexp ( [ :export , [ 'P4PORT' , 'ssl:perforce.assembla.com' ] ] ) }
23+ it { is_expected . to include_sexp ( [ :cmd , 'p4 trust -y' ] ) }
24+ it { is_expected . to include_sexp ( key_sexp ) }
25+ it { is_expected . to include_sexp ( tickets_sexp ) }
26+ it { is_expected . to include_sexp ( client_sexp ) }
27+ it { is_expected . to include_sexp ( [ :cmd , 'p4 -v ssl.client.trust.name=1 sync -p' ] ) }
28+ it { is_expected . to include_sexp ( [ :cd , 'tempdir' , echo : true ] ) }
29+ it { is_expected . not_to include_sexp ( [ :mkdir , '~/.ssh' , recursive : true ] ) }
30+
31+ context 'when repository is not from Assembla' do
32+ let ( :payload_name ) { :perforce_non_assembla }
33+
34+ it { is_expected . to include_sexp ( [ :export , [ 'P4USER' , 'travisuser' ] , echo : true ] ) }
35+ it { is_expected . not_to include_sexp ( key_sexp ) }
36+ it { is_expected . to include_sexp ( [ :export , [ 'P4PASSWD' , 'mybuildtoken' ] ] ) }
37+ it { is_expected . not_to include_sexp ( tickets_sexp ) }
38+ end
39+
40+ context 'when the job is a PR' do
41+ let ( :payload_name ) { :perforce_pull_request }
42+
43+ it { is_expected . not_to include ( client_sexp ) }
44+ it { is_expected . to include_sexp ( tickets_sexp ) }
45+ it { is_expected . to include_sexp ( [ :cmd , 'p4 -v ssl.client.trust.name=1 client -S //depot/main -o | p4 -v ssl.client.trust.name=1 client -i' ] ) }
46+ it { is_expected . to include_sexp ( [ :cmd , 'p4 -v ssl.client.trust.name=1 sync -p' ] ) }
47+ it { is_expected . to include_sexp ( [ :cmd , 'p4 -v ssl.client.trust.name=1 merge //depot/newfeature/... //depot/main/...' ] ) }
48+ it { is_expected . to include_sexp ( [ :cmd , 'p4 -v ssl.client.trust.name=1 resolve -am' ] ) }
49+ end
50+ end
51+ end
0 commit comments