From be885367df41161c94fcfe2d5c799a4bbbdfd11e Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Mon, 17 Oct 2022 15:30:21 +0100 Subject: [PATCH] Increase test coverage. --- cmd/main_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/cmd/main_test.go b/cmd/main_test.go index a27ff4c..684c15e 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -581,3 +581,52 @@ func (suite *Tests) Test_parseExistingSemver() { }) } } + +func (suite *Tests) TestSetup_ListExistingTags() { + type fields struct { + RepositoryName string + RepositoryLocalPath string + RepositoryHandler *git.Repository + LocalConfigFile string + Commits []CommitDetails + Semver SemVer + Wording Wording + Force Force + } + + tests := []struct { + name string + fields fields + noTags bool + }{ + { + name: "List tags from existing repository", + fields: fields{ + RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client", + }, + noTags: false, + }, + { + name: "List tags from non-existing repository", + fields: fields{ + RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead", + }, + noTags: true, + }, + } + for _, tt := range tests { + suite.T().Run(tt.name, func(t *testing.T) { + s := &Setup{} + s.ReadConfig(tt.fields.LocalConfigFile) + s.RepositoryName = tt.fields.RepositoryName + s.Force = tt.fields.Force + s.Prepare() + s.ListExistingTags() + if tt.noTags { + assert.Equal(len(s.Tags), 0, "Unexpected number of tags in "+tt.name) + } else { + assert.GreaterOrEqual(len(s.Tags), 1, "Unexpected number of tags in "+tt.name) + } + }) + } +}