Skip to content
Merged
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
8 changes: 6 additions & 2 deletions modules/har/pkg/har/migrate/adapter/har/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ func (a *harAdapter) UploadFile(
err = a.client.uploadSwiftFile(registry, f.Name, file, artifactName, version)
case types.DART:
err = a.client.uploadDartFile(registry, artifactName, version, f, file)
case types.RAW:
case types.RAW, types.CRAN:
err = a.client.uploadRawFile(registry, f, file)
case types.DEBIAN:
err = a.client.uploadDebianFile(registry, f, file, metadata)
case types.PUPPET:
err = a.client.uploadPuppetFile(registry, f, file)
case types.RUBY:
err = a.client.uploadRubyFile(registry, f, file)
case types.TERRAFORM:
err = a.client.uploadTerraformFile(registry, f, artifactName, version, file)
case types.CONAN:
err = a.client.uploadConanFile(registry, file, metadata)
default:
Expand Down Expand Up @@ -157,7 +161,7 @@ func (a *harAdapter) VersionExists(ctx context.Context, p types.Package, registr
}

func (a *harAdapter) FileExists(ctx context.Context, registryRef, pkg, version string, file *types.File, artifactType types.ArtifactType) (bool, error) {
if artifactType == types.RAW {
if artifactType == types.RAW || artifactType == types.CRAN {
return a.client.headRawFile(registryRef, file.Uri)
}
return a.client.artifactFileExists(ctx, registryRef, pkg, version, file, artifactType)
Expand Down
65 changes: 65 additions & 0 deletions modules/har/pkg/har/migrate/adapter/har/adapter_terraform_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package har

import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/harness/cli/modules/har/pkg/har/migrate/types"

"github.com/rs/zerolog"
)

// TestUploadFileTerraformRouting verifies that adapter.UploadFile dispatches
// TERRAFORM to uploadTerraformFile (module and provider paths).
func TestUploadFileTerraformRouting(t *testing.T) {
tests := []struct {
name string
fileName string
pkg string
version string
wantPathHas string
}{
{
name: "module routed correctly",
fileName: "vpc-1.0.0.tar.gz",
pkg: "hashicorp/vpc/aws",
version: "1.0.0",
wantPathHas: "/hashicorp/vpc/aws/1.0.0",
},
{
name: "provider routed correctly",
fileName: "terraform-provider-aws_2.0.0_linux_amd64.zip",
pkg: "hashicorp/aws",
version: "2.0.0",
wantPathHas: "/hashicorp/aws/2.0.0",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var gotPath string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotPath = r.URL.Path
w.WriteHeader(http.StatusCreated)
}))
defer srv.Close()

c := newTestClient(t, srv.URL)
a := &harAdapter{client: c, logger: zerolog.Nop()}

f := &types.File{Name: tt.fileName, Uri: "/" + tt.fileName}
body := io.NopCloser(strings.NewReader("bytes"))

err := a.UploadFile("reg1", body, f, http.Header{}, tt.pkg, tt.version, types.TERRAFORM, nil)
if err != nil {
t.Fatalf("UploadFile error: %v", err)
}
if !strings.Contains(gotPath, tt.wantPathHas) {
t.Errorf("path = %q, want to contain %q", gotPath, tt.wantPathHas)
}
})
}
}
Loading
Loading