blob: 8866f6421b49582e1271d6797f0c7e9e98c6e709 [file] [log] [blame]
package repo
import (
"context"
"encoding/base64"
"github.com/golang/mock/gomock"
gitilespb "go.chromium.org/luci/common/proto/gitiles"
"net/http"
"testing"
"testplans/internal/git"
)
func TestFetchFilesFromGitiles_success(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
// This is a base64-encoded .tar.gz file containing a snapshot of external full.xml and
// _remotes.xml. I apologize to your eyes. This is a good representation of what comes back from
// the Gitiles Archive call though.
base64Enc := `H4sIAAAAAAAA/+1dW5PbuLH2s34FM3nYqolJ3UfSlu3E5XXO2ap47ePL2cqTDIKgBIskGIDUWPn1aYAX3SCyOZ6xU8lwa7wjsfvrbqDR6AZBzNvff3v9/sOTB70Gw8HgZjJxBsV1+v/BcDpzhuPJbDCdzqaTqQP005vZE2fwsGoVV64yIp8MvlnWqXH3oNr3uOiXmAYiIVHwF7qWIuZ57Am56kUkFkn2RSRMHd9IWJCs8h1L/rISYhUxj4q4p8gmYjw5ptySlDN5/N2PNvfxOrnev375y5vXXhw8oIyW8T+aTAYn4384HIwfx//3uK6vr51EZKx3ff3rm3dv3398+dvH6+ufnVdrkqyYcjLhZGuuHMlS4cTQWA6JlHB85sQkYA5P4DZzUsm3JNPfJSFTWc9QP1tnWap+7vdNBGAuTzImIdJ4ReBQIpfUhI+SQKg+8HMNUNO+8Hov80zEAB44apdQkJzdMpY4Z6QOSYL6WwdUBrOcHcscBT95CkBJ8NRoS0vbjDnX2p5rbZCGBynGYm1ZKEmfiiTkKyfkEetVWi61dcrTfuM5v/NsLfLMNFKBbmy/5VHkJGzLpEZOOd0Acp46/s559X8eNPZ1r/dH570m/R8p8lT1zO+gtYbIhIjgF5I5t8zJlf5CW0ZWzIFGcyJBwVy6ZnQDopXn/Jo5KZGKGe5e3QYqZZSHHCSDWI37OWAhyaPM+xpHn41RnvMRvk9IDMihoam5KUlA957YghGSB9DkueLJyvnsxp89520C7SjyKCj8wSjj6IYgjsp93eSneIa7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U33pRHkiv9h4DMscCQIScBkUH1gtClMFIdZm6pH/a3tKT7/EsLj9fj9Xg9Xo/X4/Xvc/0LEpszawB4AAA=`
// Override because this is the name of the file in the above base64 gibberish.
rootXml = "full.xml"
encodedZip, err := base64.StdEncoding.DecodeString(base64Enc)
if err != nil {
t.Error(err)
}
gitilesMock := gitilespb.NewMockGitilesClient(ctl)
gitilesMock.EXPECT().Archive(gomock.Any(), gomock.Any()).Times(2).Return(
&gitilespb.ArchiveResponse{
Contents: encodedZip,
},
nil,
)
git.MockGitiles = gitilesMock
m, err := GetRepoToSourceRootFromManifests(http.DefaultClient, context.Background(), "master")
if err != nil {
t.Error(err)
}
if len(m) != 176 {
t.Errorf("expected %d project mappings, found %d", 176, len(m))
}
// Make sure that a sample project is present.
if m["chromiumos/platform/mosys"] != "src/platform/mosys" {
t.Errorf("expected to find a mapping for mosys repo. Got mappings: %v", m)
}
}