Welcome to mirror list, hosted at ThFree Co, Russian Federation.

nuget_repository_spec.rb « 5_package « browser_ui « features « specs « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0d84d82e51903e0db51384eb6546abfa7d5ec85 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# frozen_string_literal: true

require 'securerandom'

module QA
  RSpec.describe 'Package', :orchestrated, :packages do
    describe 'NuGet Repository' do
      include Runtime::Fixtures
      let(:project) do
        Resource::Project.fabricate_via_api! do |project|
          project.name = 'nuget-package-project'
          project.template_name = 'dotnetcore'
        end
      end

      let(:package) do
        Resource::Package.new.tap do |package|
          package.name = "dotnetcore-#{SecureRandom.hex(8)}"
          package.project = project
        end
      end

      let(:another_project) do
        Resource::Project.fabricate_via_api! do |project|
          project.name = 'nuget-package-install-project'
          project.template_name = 'dotnetcore'
        end
      end

      let!(:runner) do
        Resource::Runner.fabricate! do |runner|
          runner.name = "qa-runner-#{Time.now.to_i}"
          runner.tags = ["runner-for-#{project.name}"]
          runner.executor = :docker
          runner.project = project
        end
      end

      let!(:another_runner) do
        Resource::Runner.fabricate! do |runner|
          runner.name = "qa-runner-#{Time.now.to_i}"
          runner.tags = ["runner-for-#{another_project.name}"]
          runner.executor = :docker
          runner.project = another_project
        end
      end

      after do
        runner.remove_via_api!
        another_runner.remove_via_api!
        package.remove_via_api!
      end

      it 'publishes a nuget package at the project level, installs and deletes it at the group level', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1073' do
        Flow::Login.sign_in

        Resource::Repository::Commit.fabricate_via_api! do |commit|
          commit.project = project
          commit.commit_message = 'Add .gitlab-ci.yml'
          commit.update_files(
            [
                {
                    file_path: '.gitlab-ci.yml',
                    content: <<~YAML
                      image: mcr.microsoft.com/dotnet/sdk:5.0

                      stages:
                        - deploy

                      deploy:
                        stage: deploy
                        script:
                          - dotnet restore -p:Configuration=Release
                          - dotnet build -c Release
                          - dotnet pack -c Release -p:PackageID=#{package.name}
                          - dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
                          - dotnet nuget push "bin/Release/*.nupkg" --source gitlab
                        only:
                          - "#{project.default_branch}"
                        tags:
                          - "runner-for-#{project.name}"
                    YAML
                }
            ]
          )
        end

        project.visit!
        Flow::Pipeline.visit_latest_pipeline

        Page::Project::Pipeline::Show.perform do |pipeline|
          pipeline.click_job('deploy')
        end

        Page::Project::Job::Show.perform do |job|
          expect(job).to be_successful(timeout: 800)
        end

        another_project.visit!

        Resource::Repository::Commit.fabricate_via_api! do |commit|
          commit.project = another_project
          commit.commit_message = 'Add new csproj file'
          commit.add_files(
            [
                {
                    file_path: 'otherdotnet.csproj',
                    content: <<~EOF
                        <Project Sdk="Microsoft.NET.Sdk">

                          <PropertyGroup>
                            <OutputType>Exe</OutputType>
                            <TargetFramework>net5.0</TargetFramework>
                          </PropertyGroup>

                        </Project>
                    EOF
                }
            ]
          )
          commit.update_files(
            [
                {
                    file_path: '.gitlab-ci.yml',
                    content: <<~YAML
                        image: mcr.microsoft.com/dotnet/sdk:5.0

                        stages:
                          - install

                        install:
                          stage: install
                          script:
                           - dotnet nuget locals all --clear
                           - dotnet nuget add source "$CI_SERVER_URL/api/v4/groups/#{another_project.group.id}/-/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
                           - "dotnet add otherdotnet.csproj package #{package.name} --version 1.0.0"
                          only:
                            - "#{another_project.default_branch}"
                          tags:
                            - "runner-for-#{another_project.name}"
                    YAML
                }
            ]
          )
        end

        Flow::Pipeline.visit_latest_pipeline

        Page::Project::Pipeline::Show.perform do |pipeline|
          pipeline.click_job('install')
        end

        Page::Project::Job::Show.perform do |job|
          expect(job).to be_successful(timeout: 800)
        end

        project.group.sandbox.visit!

        Page::Group::Menu.perform(&:go_to_group_packages)

        Page::Project::Packages::Index.perform do |index|
          expect(index).to have_package(package.name)
          index.click_package(package.name)
        end

        Page::Project::Packages::Show.perform(&:click_delete)

        Page::Project::Packages::Index.perform do |index|
          expect(index).to have_content("Package deleted successfully")
          expect(index).not_to have_package(package.name)
        end
      end
    end
  end
end