This commit is contained in:
Sergey Zhemoytel 2024-11-19 23:13:06 +03:00
parent 499b064598
commit 9071500bbf
9 changed files with 49 additions and 10 deletions

View file

@ -3,7 +3,6 @@ package artifact_types
import (
"fmt"
"regexp"
"strings"
)
type RpmArtifact struct {

View file

@ -1,7 +1,6 @@
package config
import (
"log"
"os"
"gopkg.in/yaml.v3"

View file

@ -7,7 +7,7 @@ import (
)
func TestLoadConfig(t *testing.T) {
configFile := "config.yaml"
configFile := "../tests/config.yaml"
cfg, err := LoadConfig(configFile)
assert.NoError(t, err)
assert.NotNil(t, cfg)

View file

@ -2,7 +2,6 @@ package core
import (
"flag"
"fmt"
"tvoygit.ru/djam/artmigrator/config"
"tvoygit.ru/djam/artmigrator/logger"

3
go.mod
View file

@ -1,4 +1,4 @@
module github.com/yourusername/art_migrator
module tvoygit.ru/djam/artmigrator
go 1.19
@ -10,4 +10,5 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
)

2
go.sum
View file

@ -6,6 +6,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=

View file

@ -1,14 +1,47 @@
// gitea_test.go
package gitea
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestArtifactExists(t *testing.T) {
client := NewClient("https://gitea.example.com", "token")
mockClient := &MockClient{}
defer mockClient.AssertExpectations(t)
mockClient.On("ArtifactExists", "owner", "repo", "test-artifact").Return(false, nil)
client := mockClient
exists, err := client.ArtifactExists("owner", "repo", "test-artifact")
assert.NoError(t, err)
assert.Equal(t, false, exists)
}
func TestArtifactExists_Error(t *testing.T) {
mockClient := &MockClient{}
defer mockClient.AssertExpectations(t)
mockClient.On("ArtifactExists", "owner", "repo", "test-artifact").Return(false, assert.AnError)
client := mockClient
exists, err := client.ArtifactExists("owner", "repo", "test-artifact")
assert.Error(t, err)
assert.Equal(t, false, exists)
}
func TestArtifactExists_ServerError(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}))
defer ts.Close()
client := NewClient(ts.URL, "token")
exists, err := client.ArtifactExists("owner", "repo", "test-artifact")
assert.Error(t, err)
assert.Equal(t, false, exists)
}

View file

@ -6,7 +6,6 @@ import (
"net/http"
"strings"
"tvoygit.ru/djam/artmigrator/logger"
)
type Client struct {

View file

@ -2,7 +2,6 @@ package nexus
import (
"testing"
"github.com/stretchr/testify/assert"
)
@ -11,4 +10,12 @@ func TestGetArtifacts(t *testing.T) {
artifacts, err := client.GetArtifacts("test-repo")
assert.NoError(t, err)
assert.NotEmpty(t, artifacts)
_, err := ParseMavenArtifact("invalid-artifact")
if err == nil {
t.Errorf("Expected error for invalid artifact, but got nil")
}
}