diff --git a/artifact_types/rpm.go b/artifact_types/rpm.go index 4667ef0..10c2e26 100644 --- a/artifact_types/rpm.go +++ b/artifact_types/rpm.go @@ -3,7 +3,6 @@ package artifact_types import ( "fmt" "regexp" - "strings" ) type RpmArtifact struct { diff --git a/config/config.go b/config/config.go index 08ad3e4..9858cb4 100644 --- a/config/config.go +++ b/config/config.go @@ -1,7 +1,6 @@ package config import ( - "log" "os" "gopkg.in/yaml.v3" diff --git a/config/config_test.go b/config/config_test.go index 7d97a2b..585b46f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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) diff --git a/core/core.go b/core/core.go index e29be64..b37a351 100644 --- a/core/core.go +++ b/core/core.go @@ -2,7 +2,6 @@ package core import ( "flag" - "fmt" "tvoygit.ru/djam/artmigrator/config" "tvoygit.ru/djam/artmigrator/logger" diff --git a/go.mod b/go.mod index 0c7e528..0d3dd08 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 6f0f12e..3b53c2a 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/repository/gitea/gitea_test.go b/repository/gitea/gitea_test.go index 650d35c..1cc3389 100644 --- a/repository/gitea/gitea_test.go +++ b/repository/gitea/gitea_test.go @@ -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) -} \ No newline at end of file +} + +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) +} diff --git a/repository/nexus/nexus.go b/repository/nexus/nexus.go index 6246ea0..83bc446 100644 --- a/repository/nexus/nexus.go +++ b/repository/nexus/nexus.go @@ -6,7 +6,6 @@ import ( "net/http" "strings" - "tvoygit.ru/djam/artmigrator/logger" ) type Client struct { diff --git a/repository/nexus/nexus_test.go b/repository/nexus/nexus_test.go index 1e627b0..8f803cc 100644 --- a/repository/nexus/nexus_test.go +++ b/repository/nexus/nexus_test.go @@ -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) -} \ No newline at end of file + + _, err := ParseMavenArtifact("invalid-artifact") + if err == nil { + t.Errorf("Expected error for invalid artifact, but got nil") + } + +} + +