46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package index
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
"net/http"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"tea.karlcom.de/karl/bucketeer/internal/model"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestListAzureContainerDiscovery(t *testing.T) {
|
||
|
|
// Account listing is unavailable; only the "images" container is public.
|
||
|
|
blobXML := `<?xml version="1.0" encoding="utf-8"?><EnumerationResults ContainerName=".../images"><Blobs>
|
||
|
|
<Blob><Name>a.gif</Name><Properties><Content-Length>123</Content-Length><Content-Type>image/gif</Content-Type><Last-Modified>Thu, 06 Nov 2025 13:05:52 GMT</Last-Modified><Etag>0x1</Etag></Properties></Blob>
|
||
|
|
</Blobs></EnumerationResults>`
|
||
|
|
x, _ := newTestIndexer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
if r.URL.Path == "/images" && r.URL.Query().Get("comp") == "list" {
|
||
|
|
_, _ = w.Write([]byte(blobXML))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
w.WriteHeader(http.StatusNotFound)
|
||
|
|
}))
|
||
|
|
// The test server host is 127.0.0.1:port; listAzure is called with c.Hostname.
|
||
|
|
entries, err := x.List(context.Background(), model.Candidate{
|
||
|
|
Hostname: strings.TrimPrefix(x.gcsBase, "http://"), Resource: "acct",
|
||
|
|
Provider: model.ProviderAzure, Service: model.ServiceBlobStorage,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if len(entries) != 1 || entries[0].Name != "images/a.gif" || entries[0].Size != 123 {
|
||
|
|
t.Fatalf("unexpected entries: %+v", entries)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestAzureContainersIncludesAccount(t *testing.T) {
|
||
|
|
got := AzureContainers("myappdev")
|
||
|
|
joined := fmt.Sprint(got)
|
||
|
|
for _, want := range []string{"images", "myappdev", "myapp"} {
|
||
|
|
if !strings.Contains(joined, want) {
|
||
|
|
t.Fatalf("AzureContainers missing %q: %v", want, got)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|