Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MONGO_HOST=127.0.0.1
MONGO_PORT=27017
MONGO_USER=admin
MONGO_PASSWORD=secret
MONGO_DB=gitlab_lint
7 changes: 7 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:8888', // ajuste se necessário
},
});
68 changes: 68 additions & 0 deletions cypress/e2e/gitlab-lint-api.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/// <reference types="cypress" />

describe('GitLab Lint API - Endpoints Existentes', () => {

// ----------------------------
// Testes positivos
// ----------------------------
it('GET / deve responder 200 e retornar informações da API', () => {
cy.request('/')
.then((res) => {
// Status
expect(res.status).to.eq(200);

// Corpo
expect(res.body).to.have.property('name', 'gitlab-lint API');
expect(res.body).to.have.property('version');

// Tipo de dado
expect(res.body.name).to.be.a('string');
expect(res.body.version).to.match(/\d+\.\d+\.\d+/);
});
});

it('GET / é idempotente (resposta consistente em múltiplas chamadas)', () => {
cy.request('/').then(res1 => {
cy.request('/').then(res2 => {
expect(res1.body).to.deep.eq(res2.body);
});
});
});

it('GET / retorna JSON parseável', () => {
cy.request('/')
.then(res => {
expect(() => JSON.parse(JSON.stringify(res.body))).not.to.throw();
});
});

it('GET / responde rapidamente (menos de 500ms)', () => {
cy.request('/')
.then(res => {
expect(res.duration).to.be.lessThan(500);
});
});

// ----------------------------
// Testes negativos
// ----------------------------
it('POST / não é permitido (deve retornar 404 ou 405)', () => {
cy.request({
method: 'POST',
url: '/',
failOnStatusCode: false
}).then(res => {
expect(res.status).to.be.oneOf([404, 405]);
});
});

it('GET / ignora cabeçalhos desconhecidos', () => {
cy.request({
url: '/',
headers: { 'X-Test-Header': '123' }
}).then(res => {
expect(res.status).to.eq(200);
});
});

});
2 changes: 2 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Arquivo de comandos customizados do Cypress
// Aqui você pode criar helpers globais (opcional)
7 changes: 7 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// ***********************************************************
// Este arquivo é processado automaticamente antes dos testes.
// Use-o para adicionar comandos ou hooks globais se quiser.
// ***********************************************************

// Importa comandos customizados (se você tiver algum)
import './commands';
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/globocom/gitlab-lint
go 1.15

require (
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/getsentry/sentry-go v0.9.0
github.com/go-openapi/spec v0.20.3 // indirect
Expand All @@ -16,11 +17,13 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/viper v1.7.1
github.com/swaggo/echo-swagger v1.1.0
github.com/swaggo/swag v1.7.0
github.com/stretchr/testify v1.10.0 // indirect
github.com/swaggo/echo-swagger v1.0.0
github.com/swaggo/swag v1.6.7
github.com/xanzy/go-gitlab v0.43.0
go.mongodb.org/mongo-driver v1.7.3
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/tools v0.1.0 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading