github.com/zaquestion/lab@v0.25.1/cmd/ci_status_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func Test_ciStatus(t *testing.T) {
    13  	t.Parallel()
    14  	repo := copyTestRepo(t)
    15  	cmd := exec.Command("git", "fetch", "origin")
    16  	cmd.Dir = repo
    17  	if b, err := cmd.CombinedOutput(); err != nil {
    18  		t.Log(string(b))
    19  		t.Fatal(err)
    20  	}
    21  
    22  	cmd = exec.Command("git", "checkout", "-b", "ci_test_pipeline")
    23  	cmd.Dir = repo
    24  	if b, err := cmd.CombinedOutput(); err != nil {
    25  		t.Log(string(b))
    26  		t.Fatal(err)
    27  	}
    28  
    29  	cmd = exec.Command("git", "branch", "-m", "local/ci_test_pipeline")
    30  	cmd.Dir = repo
    31  	if b, err := cmd.CombinedOutput(); err != nil {
    32  		t.Log(string(b))
    33  		t.Fatal(err)
    34  	}
    35  
    36  	cmd = exec.Command(labBinaryPath, "ci", "status")
    37  	cmd.Dir = repo
    38  
    39  	b, err := cmd.CombinedOutput()
    40  	if err != nil {
    41  		t.Log(string(b))
    42  		t.Fatal(err)
    43  	}
    44  	out := string(b)
    45  	assert.Contains(t, out, `Stage:  Name                           - Status
    46  build:  build1                         - success
    47  deploy: deploy1                        - success
    48  deploy: deploy5:really_a_long_name_for - success
    49  deploy: deploy9                        - success
    50  build:  build2                         - success
    51  deploy: deploy4                        - success
    52  test:   test1                          - success
    53  deploy: deploy7                        - success
    54  test:   test3                          - success
    55  deploy: deploy3:no_sufix:deploy        - success
    56  deploy: deploy5                        - success
    57  deploy: deploy2                        - success
    58  deploy: deploy6                        - success
    59  deploy: deploy10                       - success
    60  deploy: deploy8                        - success
    61  build:  build2:fails                   - failed
    62  test:   test2                          - success
    63  test:   test2:no_suffix:test           - success
    64  test:   test2:really_a_long_name_for   - success`)
    65  
    66  	assert.Contains(t, out, "Pipeline Status: success")
    67  }
    68  
    69  func Test_ciStatusMR(t *testing.T) {
    70  	t.Parallel()
    71  	repo := copyTestRepo(t)
    72  	cmd := exec.Command(labBinaryPath, "ci", "status", "--merge-request", "17")
    73  	cmd.Dir = repo
    74  
    75  	b, err := cmd.CombinedOutput()
    76  	if err != nil {
    77  		t.Log(string(b))
    78  		t.Fatal(err)
    79  	}
    80  	out := string(b)
    81  	if strings.TrimSpace(os.Getenv("LAB_CORE_TEST")) == "GITLAB" {
    82  		assert.Contains(t, out, `Stage:  Name                           - Status
    83  build:  build1                         - success
    84  build:  build2                         - success
    85  build:  build2:fails                   - failed
    86  test:   test1                          - success
    87  test:   test2                          - success
    88  test:   test2:really_a_long_name_for   - success
    89  test:   test2:no_suffix:test           - success
    90  test:   test3                          - success
    91  deploy: deploy1                        - success
    92  deploy: deploy2                        - manual
    93  deploy: deploy3:no_sufix:deploy        - success
    94  deploy: deploy4                        - success
    95  deploy: deploy5:really_a_long_name_for - success
    96  deploy: deploy5                        - success
    97  deploy: deploy6                        - success
    98  deploy: deploy7                        - success
    99  deploy: deploy8                        - success
   100  deploy: deploy9                        - success
   101  deploy: deploy10                       - success`)
   102  	}
   103  
   104  	assert.Contains(t, out, "Pipeline Status: success")
   105  }