From ee1f2c01529f276847d732e9a4d9062c942af7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=22BKC=22=20Carlb=C3=A4cker?= Date: Fri, 7 Apr 2017 10:16:45 +0200 Subject: [PATCH] tests --- models/fixtures/commit_status.yml | 54 +++++++++++++++++++++++++++++++ models/status_test.go | 41 +++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 models/fixtures/commit_status.yml create mode 100644 models/status_test.go diff --git a/models/fixtures/commit_status.yml b/models/fixtures/commit_status.yml new file mode 100644 index 0000000000000..1c5f102a1a27c --- /dev/null +++ b/models/fixtures/commit_status.yml @@ -0,0 +1,54 @@ +- + id: 1 + index: 1 + repo_id: 1 + state: pending + sha: 1234123412341234123412341234123412341234 + target_url: https://example.com/builds/ + description: My awesome CI-service + context: ci/awesomeness + creator_id: 2 + +- + id: 2 + index: 2 + repo_id: 1 + state: warning + sha: 1234123412341234123412341234123412341234 + target_url: https://example.com/converage/ + description: My awesome Coverage service + context: cov/awesomeness + creator_id: 2 + +- + id: 3 + index: 3 + repo_id: 1 + state: success + sha: 1234123412341234123412341234123412341234 + target_url: https://example.com/converage/ + description: My awesome Coverage service + context: cov/awesomeness + creator_id: 2 + +- + id: 4 + index: 4 + repo_id: 1 + state: failed + sha: 1234123412341234123412341234123412341234 + target_url: https://example.com/builds/ + description: My awesome CI-service + context: ci/awesomeness + creator_id: 2 + +- + id: 5 + index: 5 + repo_id: 1 + state: error + sha: 1234123412341234123412341234123412341234 + target_url: https://example.com/builds/ + description: My awesome deploy service + context: deploy/awesomeness + creator_id: 2 diff --git a/models/status_test.go b/models/status_test.go new file mode 100644 index 0000000000000..3a3dea3a4c2e3 --- /dev/null +++ b/models/status_test.go @@ -0,0 +1,41 @@ +// Copyright 2017 Gitea. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// +build disabled + +package models + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetCommitStatuses(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) + + sha1 := "1234123412341234123412341234123412341234" + + statuses, err := GetCommitStatuses(repo1, sha1, 0) + assert.NoError(t, err) + if assert.Equal(t, 5, len(statuses), "Expected to get 5 statuses") { + + assert.Equal(t, statuses[0].Context, "ci/awesomeness") + assert.Equal(t, statuses[0].State, CommitStatusPending) + + assert.Equal(t, statuses[1].Context, "cov/awesomeness") + assert.Equal(t, statuses[1].State, CommitStatusWarning) + + assert.Equal(t, statuses[2].Context, "cov/awesomeness") + assert.Equal(t, statuses[2].State, CommitStatusSuccess) + + assert.Equal(t, statuses[3].Context, "ci/awesomeness") + assert.Equal(t, statuses[3].State, CommitStatusFailure) + + assert.Equal(t, statuses[4].Context, "ci/awesomeness") + assert.Equal(t, statuses[4].State, CommitStatusError) + } +}